如何在Postgresql中查询jsonb中的Json数组

如何在Postgresql中查询jsonb中的Json数组,sql,arrays,json,postgresql,jsonb,Sql,Arrays,Json,Postgresql,Jsonb,我有一个jsonb列,它有以下行 第1行: [ { "cpe23Uri": "cpe:2.3:a:sgi:irix:3.55:*:*:*:*:*:*:*", "active": true }, { "cpe23Uri": "cpe:2.3:a:university_of_washington:imap:10.234:*:*:*:*:*:*:*", "a

我有一个jsonb列,它有以下行

第1行:

 [
        {
            "cpe23Uri": "cpe:2.3:a:sgi:irix:3.55:*:*:*:*:*:*:*",
            "active": true
        },
        {
            "cpe23Uri": "cpe:2.3:a:university_of_washington:imap:10.234:*:*:*:*:*:*:*",
            "active": true
        }
    ]
第2行:

 []
第3行:

[
    {
        "cpe23Uri": "cpe:2.3:o:sgi:irix:*:*:*:*:*:*:*:*",
        "active": true
    }
]
我想在键cpe23Uri中找到包含sgi:irix的行


我应该使用哪个查询来获得最佳性能

您可以将
exists
条件与相关子查询一起使用,该子查询使用
jsonb\u array\u element()
取消对数组的测试和搜索:

select *
from mytable t
where exists (
    select 1
    from jsonb_array_elements(t.js) x
    where  x->>'cpe23Uri' like '%sgi:irix%'
);

它工作得很好!有没有办法让它更快?因为它需要大约3秒钟才能得到结果。我必须运行这个查询一个大的时间,可能需要1个月,所以。。有什么想法吗?从t中选择*,其中t.products@>'[{“cpe23Uri:“cpe:2.3:a:sgi:irix:0.1.0:*”::jsonb;此查询只需1秒,但没有LIKE运算符。。