I am running PostgreSQL 9.3.4. I have a table with 3 columns:
id | name | addr
---|----|----
1 | n1 | ad1
2 | n2 | ad2
I need to move the data to a new table with a JSON column like:
id | data
---| ---
1 | {"name": "n1", "addr": "ad1"}
2 | {"name": "n2", "addr": "ad2"}
I tried:
SELECT t.id, row_to_json(t) AS data
FROM (SELECT id, name, addr FROM myt) t;
But that includes
id
in the result. So row_to_json
is not the solution for me.
Is there a way to get only the columns I need (name
& addr
)?
Asked by AliBZ
(1827 rep)
Feb 2, 2015, 09:30 PM
Last activity: Sep 22, 2023, 12:00 AM
Last activity: Sep 22, 2023, 12:00 AM