jumpman23
jumpman23

Reputation: 395

Insert Statement - From Temp Table

I am currently trying to insert data into a Redshift table from multiple temporary tables that I have created.

Insert into schema.table1 (

with a as (
select t1.country_code, t1.country_name
from t1
)

select * from a
);

The error that I get on this statement says the following: Amazon Invalid operation: syntax error at or near "as";. What do I need to change in order to be able to insert data from a temp table?

Upvotes: 0

Views: 307

Answers (2)

Kiran
Kiran

Reputation: 46

I just tried this and it worked for me.

insert into tempt1 ( with a as (select a from tempt2) select * from a);

Upvotes: 0

demircioglu
demircioglu

Reputation: 3465

Is it not possible to run the command like this if you have same table structures in both schema.table1 and t1

insert into schema.table1 
select t1.country_code, t1.country_name
from t1;

One other thing you might want to check is, in your SQL table1 is in 'schema' but t1 is referred without a schema so it's in public, make sure you don't have two t1s with different structures.

Upvotes: 1

Related Questions