我想通过特定的字段操作检索数据,它存储对象的数组。我想在其中添加新对象。
CREATE TABLE justjson ( id INTEGER, doc JSONB);
INSERT INTO justjson VALUES ( 1, '[
{
"name": "abc",
"age": "22"
},
{
"name": "def",
"age": "23"
}
]');
检索年龄大于等于23的数据
答案 0 :(得分:0)
例如using jsonb_array_elements
:
t=# with a as (select *,jsonb_array_elements(doc) k from justjson)
select k from a where (k->>'age')::int >= 23;
k
------------------------------
{"age": "23", "name": "def"}
(1 row)