pgsql 查询jsonb中包含某个键值对的表记录
表名 table_name ,字段 combos 类型为 jsonb 可为空,示例内容如下,
$arr_combos = [
['id' => '1001', 'value' => 'zs' ],
['id' => '1002', 'value' => 'ls' ]
]
查询表中jsonb字段中包含id=1001的记录的sql语句 :
SELECT * FROM table_name
WHERE
(SELECT * FROM jsonb_array_elements_text(combos) AS ab
WHERE (ab::json->>'id') = '1001') is not null;