我有一个带有“规则”列的表,如下所示:
{"111_abc":0,"222_def":0,"333_abs":0}
我想编写一个postgres查询,以将其转换为如下形式:
rules
111_abc
222_def
333_abs
我尝试了几种json_extract_path或json_array_element的再现方法-真不走运。
请帮助
答案 0 :(得分:1)
使用功能jsonb_object_keys()
,例如:
with my_table(rules) as (
values
('{"111_abc":0,"222_def":0,"333_abs":0}'::jsonb)
)
select jsonb_object_keys(rules) as rules
from my_table;
rules
---------
111_abc
222_def
333_abs
(3 rows)
答案 1 :(得分:0)
select * from json_each_text('{"111_abc":0,"222_def":0,"333_abs":0}')