Skip to content
Advertisement

How to insert column of other table in postgresql

I want to insert a column of other table and one parameter of this table have a hard coded value. I want to iterate this value with the each return value of other table column. How can i do this with insert query?

let 3,4,6 is the return column value of other table.

insert into table(value1,value2)
values (2,select id from table2)

Return column

2       3
2       4
2       6

Advertisement

Answer

Get rid of the values clause:

insert into table(value1,value2)
select 2, id 
from table2
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement