Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert Column into Table with many Columns Postgresql

Tags:

postgresql

My first table(t1) is a simple list of websites.

url

My second table(t2) has two columns

url, source

I would like to do something like this

insert into t2(url, source) where ((select * from t1), '1');

But I am getting an error that I have to many rows from my select * from t1. I understand why I am getting the error, but how should I do this query instead?

The reason why I am not editing t1 is that I have many different "t1"s that I would like to mark in my new master table as different with the sourceIDs.

like image 950
Dan Ciborowski - MSFT Avatar asked Mar 23 '26 02:03

Dan Ciborowski - MSFT


1 Answers

If you want to copy the values of the url column from table t1 into the url column of table t2 and at the same time fill the source column with the value '1' then you can do it like this

INSERT INTO t2(url, source) SELECT url, '1' FROM t1;
like image 188
Ma3x Avatar answered Mar 25 '26 19:03

Ma3x