Is there a straightforward way to put entire row from one Postgres table into a JSON column in another table?
Here's an example to illustrate what I'm looking to do. Let's say I've got a table people, with name, age, and data columns:
column type
-----------
name text
age int
data json
I'd like to merge in my table of 2012_customers, which has a lot more columns. How would I stuff all those extra columns into the JSON column of people, preserving the column names as the data keys? Here's some pseudo-SQL for that:
insert into people
select
name,
age,
all_fields_as_json() as json
from customers_2012
row_to_jsonnot do what you need?to_jsonprobably does what I want, but I haven't been able to figure out the correct syntax for the example above.select name, age, row_to_json(customers_2012) from customers_2012as your select part.