我怎样才能在 JSON 数组对象 Postgres 字段中做小于、大于?
How can I do less than, greater than in JSON array object Postgres fields?
我想通过存储对象数组的特定字段操作检索数据。我想在其中添加新对象。
CREATE TABLE justjson ( id INTEGER, doc JSONB);
INSERT INTO justjson VALUES ( 1, '[
{
"name": "abc",
"age": "22"
},
{
"name": "def",
"age": "23"
}
]');
检索年龄大于等于 23 的数据怎么可能
例如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)
我想通过存储对象数组的特定字段操作检索数据。我想在其中添加新对象。
CREATE TABLE justjson ( id INTEGER, doc JSONB);
INSERT INTO justjson VALUES ( 1, '[
{
"name": "abc",
"age": "22"
},
{
"name": "def",
"age": "23"
}
]');
检索年龄大于等于 23 的数据怎么可能
例如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)