I have Postgres column of JSONB array of objects, looking like this :
[{"key": "meetingDate", "value": "2022-08-22"}, {"key": "userName", "value": "Testing User"}]
how can i get the result like this
meetingDate | userName |
---|---|
2022-08-22 | TestingUser |
2
Answers
Use json_array_elements (db fiddle here).
You can use a JSON path expression:
jsonb_path_query_first
returns ajsonb
value, but there is no direct cast from there totext
. The#>> '{}'
is a small hack to convert thejsonb
value to atext
value. If you are OK with ajsonb
value, you can remove it.