Postgresql Jsonb Functions and Operators

PG 对 json 的支持真是美如画

https://www.postgresql.org/docs/9.5/functions-json.html

比如 hello 表有个 result 字段长这样

1
2
3
4
5
6
7
8
9
"result": {
        "items": [
            "warrants",
            "convertiables"
        ],
        "warrants": {
            "index": 10
        }
}

需要把index大于0的记录找出来

1
2
3
SELECT *
FROM hello
WHERE (result -> 'warrants' ->> 'index') :: INT > 0

爽的很啊

加载评论