Postgresql multiple insert with selected query

I need to execute an insert query for multiple rows in which the first column is a numeric and identical value, and the second value is retrieved from another table.

sort of

insert into the table (33, select col2 from another_table);

can this be done with a single statement?

+3
source share
2 answers

like this

insert into table 
select 33, col2 from another_table;
+12
source

If you want to specify columns in your insert request, you should use this syntax:

INSERT INTO table (id, col2_name) (SELECT 33, col2 FROM another_table);
0
source

Source: https://habr.com/ru/post/1747871/


All Articles