Is it possible to return a JSON object keys as an array of values in PostgreSQL?
In JavaScript, this would simply be Object.keys(obj)
, which returns an array of strings.
For example, if I have a table like this:
tbl_items
---------
id bigserial NOT NULL
obj json NOT NULL
And if there's a row like this:
id obj
----- -------------------------
123 '{"foo":1,"bar":2}'
How can I have a query to return:
id keys
----- ------------------
123 '{"foo","bar"}'