pgsql语法记录
官网参考资料
https://www.postgresql.org/docs/9.6/functions-json.html
查询相关语法
假设存了一个(Item表values列)jsonb数据如下
1 |
|
- 查询values中包含man_hour字符串
select * from "Item" where "values"::text like '%"man_hour"%';
- 查询指定某个字段等于某个值
select * from "Item" where ("Item".values->>'r_man_hour_plugin_date')::int8 = 1679500800000;
- 查询指定某个字段大于某个值
select * from "Item" where ("Item".values->>'r_man_hour_plugin_date')::int8 > 1679500700000;
- 查询r_man_hour_plugin_date
select values->>'DataQuotecrtttt', values->>'remote_data_quote_field_type123' from "Item"
假设数据为[{“status”: “approved”, “comment”: “”, “approver”: “I719aTBelK”, “approvalTime”: 1697018720199}] - 查询approvalTime
SELECT aa->0->'approvalTime' AS approvalTime FROM your_table;
- 多层嵌套json查询
SELECT * FROM my_table WHERE (my_table.item -> 'itemType' ->> 'objectId')::int = 1;
SELECT * FROM my_table WHERE (my_table.item ->> 'itemType')::json ->> 'objectId' = '1';
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!