1.操作符
select json字段::json->'key值' from order -- 对象域
select json字段::json->>'key值' from order -- 文本
select json字段::json#>'{key值}' from order -- 对象域
select json字段::json#>>'{key值}' from order -- 文本
对象域表示还能继续操作,而如果是文本,那就不能继续操作了
可以理解为json对象跟json文本字符串
2.查询
普通查询
select '{"sites":{"site":{"id":"1","name":"喵喵喵","url":"baidu.com"}}}'::json->'sites'->'site' -- 对象域
select '{"sites":{"site":{"id":"1","name":"喵喵喵","url":"baidu.com"}}}'::json->'sites'->>'site' -- 文本
数组查询
select '{"sites":{"site":[{"id":"1","name":"喵喵","url":"baidu.com"},{"id":"2","name":"喵喵","url":"bb.com"},{"id":"3","name":"喵喵","url":"baidu.com"}]}}'::json->'sites'->'site'->(0)
select '{"sites":{"site":[{"id":"1","name":"喵喵","url":"baidu.com"},{"id":"2","name":"喵喵","url":"baidu.com"},{"id":"3","name":"Google","url":"baidu.com"}]}}'::json->'sites'->'site'->(0)->>'id'
官方文档:
JSON 函数和操作符