CREATE TABLE data (obj JSONB);
INSERT INTO data (obj) VALUES ('{"a": 1, "b": 2}'::jsonb);
INSERT INTO data (obj) VALUES ('{"a": 3, "b": 4}'::jsonb);
我需要一个产生以下结果的查询:
a | b
---|---
1 | 2
3 | 4
编辑:回答
SELECT x.*
FROM data, jsonb_to_record(obj) as x(a text, b text);
答案 0 :(得分:1)
尝试类似......
CREATE TABLE lame (stuff jsonb);
INSERT INTO lame VALUES ('{"a" : 1, "b": 1}');
INSERT INTO lame VALUES ('{"a" : 2, "b": 2}');
SELECT stuff->'a' as "a", stuff->'b' as "b" FROM lame;
查找文章Faster Operations with the JSONB Data Type in PostgreSQL中的提示。
祝你好运!