I'd like to create a Postgres trigger on a table to run when a row gets inserted or updated. The table has many columns, and I'd like the trigger to insert that row into another table. But in that other table, all those columns should be combined into one JSON object (JSONB in newer versions of Postgres).
original table
column1|column2|column3 |
-------|-------|--------|
A |B |C |
new table
combined_column |
---------------------------------------|
{ column1: A, column2: B, column3: C } |
So the table that the trigger is created on would have for example 3 columns, but the table that the trigger inserts into would have only 1 column (a JSON object combining all the columns for the inserted/updated row in the original table).
row_to_json()