gpt4 book ai didi

postgresql - 我怎样才能在 JSON Postgres 字段中做小于、大于?

转载 作者:行者123 更新时间:2023-11-29 11:23:13 24 4
gpt4 key购买 nike

如果我有一些 json:

id = 1, json = {'key':95}
id = 2, json = {'key':90}
id = 3, json = {'key':50}

有没有一种方法可以使用 Postgres 字段来查询大于 >= 90 的键?

最佳答案

使用运算符->> (Get JSON object field as text) ,例如

with my_table(id, json) as (
values
(1, '{"key":95}'::json),
(2, '{"key":90}'),
(3, '{"key":50}')
)

select *
from my_table
where (json->>'key')::int >= 90;

id | json
----+------------
1 | {"key":95}
2 | {"key":90}
(2 rows)

关于postgresql - 我怎样才能在 JSON Postgres 字段中做小于、大于?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44531689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com