postgresqlamazon-redshift

Redshift ERROR: relation "Temp table" does not exist


under AWS Redshift

I created a temp table with

select all 
*
into temp table #cleaned_fact
from fact_table
limit 100

get

Executed successfully

Updated 0 rows in 0.716 seconds.

and try to check the data in temp table with

select *
from #cleaned_fact

get error

ERROR: relation "#cleaned_fact" does not exist

======================================================= update 1.

be careful

The temp table exists only for duration of your session using which you have created the table.

    create temp table IF NOT EXISTS #cleaned_fact
(
col1 INT NOT NULL encode delta,
col2 INT NOT NULL encode mostly16,
col3 INT NOT NULL encode runlength,
col4 BIGINT NOT NULL encode mostly32,
);
insert into #cleaned_fact
select *
from fact_channel_posting
limit 100

returns

Executed successfully

Updated 100 rows in 3.101 seconds.

but in another session select * from #cleaned_fact still returns the same error


Solution

  • Try in this way to create temp table

    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    [(create_definition,...)]
    [table_options]
    select_statement
    
    
    
    CREATE TEMPORARY TABLE IF NOT EXISTS mytable
    (id int(11) NOT NULL, PRIMARY KEY (id)) ENGINE=MyISAM;
    INSERT IGNORE INTO mytable SELECT id FROM table WHERE xyz;