alan
alan

Reputation: 53

postgresql multiple insert with select query

i need to perform a insert query for multiple rows whereby the first column is a numeric and identical value and the second values are queried from another table.

something like

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

can this be accomplished with a single statement?

Upvotes: 5

Views: 11868

Answers (2)

Ivan
Ivan

Reputation: 11

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

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

Upvotes: 1

SQLMenace
SQLMenace

Reputation: 135151

like this

insert into table 
select 33, col2 from another_table;

Upvotes: 13

Related Questions