If I run:
with fields as (
select jsonb_each_text(jsonb_array_elements('[
{"a":1},
{"b":2},
{"c":3}]')) x
)
select (x).key, (x).value from fields;
I get:
key | value
-----+-------
a | 1
b | 2
c | 3
(3 rows)
This works fine, but I'm looking for a way to extract these fields ( key
and value
) without having to specify them by hand. In other words, can I expand the composite-typed values from the inner query directly, without having to individually name the pieces ( key
and value
) I want to extract? This would be something like an inverse of the ROW
function (which creates a composite type from individual vaues)...
How about this?
with fields as (
select json_each_text(json_array_elements('[
{"a":1},
{"b":2},
{"c":3}]')) x
)
select (x).* from fields;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.