我在表 t1 中有一个 JSON 字段 c1,其格式为
{
"11111" : { "STATUS" : "1"},
"22222" : { "STATUS" : "0"},
"33333" : { "STATUS" : "0"}
}
我想找到 t1 中任何键状态为 1 的行,我已经尝试了以下命令
with r1 as(select t1.*, json_object_keys(c1) as keys from t1) select * from r1 where r1.c1->keys->>'STATUS' = '1';
但它没有给我任何一行?
最佳答案
select *
from t1
where exists (
select 1
from json_each(c1)
where value ->> 'STATUS' = '1'
)
关于sql - 如何使用任意键的 postgresql JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719747/