sql - How to use the key of jsonb in postgresql as a row value? -


i have table this:

id (serial) | data (jsonb) 1           | {"a": 1, "b": 2} 2           | {"a": 3, "b": 1} 

how convert table:

id | datakey | datavalue 1  |       | 1             # {"a": 1}  1  | b       | 2             # {"b": 2} 2  |       | 3             # {"a": 3} 2  | b       | 1             # {"b": 1} 

ps. character after # comment

use jsonb_each().

with my_table(id, data) ( values (1, '{"a": 1, "b": 2}'::jsonb), (2, '{"a": 3, "b": 1}') )  select id, key, value my_table, jsonb_each(data)   id | key | value  ----+-----+-------   1 |   | 1   1 | b   | 2   2 |   | 3   2 | b   | 1 (4 rows) 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -