PratikJoshi
PratikJoshi

Reputation: 3

Redshift: insert column C1 of table T1 into column C2 of Table T2

I have two tables:

T1 with columns A1, A2, A3, A4,...., A20.

T2 with columns B1, B2, B3,...., B15. The data type of all columns is varchar.

I want to copy all values of column range A1-A10 to B1-B10. How do I do so in Redshift? I tried: insert into T2(B1,B2,...,B10) select A1 A2 A3 ... A10 from T1 but it failed. I corrected errors like missing ), (dot) in the column name.

How can I insert selected column from one table to another? Is there any other way to do that?

Upvotes: 0

Views: 94

Answers (1)

ketan vijayvargiya
ketan vijayvargiya

Reputation: 5659

You need to do insert into T2 (select A1, A2 ... A10 from T1).

I tested with following queries and things worked fine for me:

create temp table T1 (a varchar(5), b varchar(5), c varchar(5), d varchar(5), e varchar(5));
insert into T1 values ('t11', 't12', 't13', 't14', 't15');
create temp table T2 (a varchar(5), b varchar(5), c varchar(5));
insert into T2 values ('t21', 't22', 't23');
insert into T2 (select a, b, c from T1);

select * from T2;

The last line correctly printed the following:

t21 t22 t23
t11 t12 t13

Upvotes: 0

Related Questions