Reputation: 337
insert into a jsonb column selecting from different table in psql. i want the jsonb insert like
{"name": "myname" ,"email": "[email protected]"}
I want to do some thing like this "name": "myname" constant value and email is select from another table
insert into test1 (column1) select {"name": "myname" ,"email": email}
Upvotes: 3
Views: 1837
Reputation: 2778
Just use row_to_json to convert the selected rows into json. Then cast to jsob if necessary.
insert into test1 (column1)
select row_to_json(x)::jsonb from (select 'myname' as name, email from another_table) x;
Upvotes: 3