我有多个jsonb列,我想从每一列中提取数据。 我正在使用postgressql。
输入:-
setUp()
输出:-
ID Jsoncol1 Jsoncol2 Jsoncol3 Date
0 {"@class": "team": {"id":"Captain","dob": [1990, 9, 11]}} {"@class": "group": {"id":"Colour","dob": [1990, 9, 11]}} {"@class": "person": {"id":"Red","dob": [1990, 9, 11]}]} 13/05/2019
答案 0 :(得分:0)
如果没有@class:
(这会使JSON值无效),则数据可能看起来像这样
id | jsoncol1 | jsoncol2 | jsoncol3 | mydate
-: | :---------------------------------------------- | :---------------------------------------------- | :-------------------------------------------- | :---------
0 | {"team": {"id":"Captain","dob": [1990, 9, 11]}} | {"group": {"id":"Colour","dob": [1990, 9, 11]}} | {"person": {"id":"Red","dob": [1990, 9, 11]}} | 2019-05-13
问题似乎在于,从JSON对象提取id
值:
SELECT
id,
jsoncol1 -> 'team' ->> 'id' AS team,
jsoncol2 -> 'group' ->> 'id' AS "group",
jsoncol3 -> 'person' ->> 'id' AS person,
mydate
FROM mytable