I want to create a temp table and call this temp table in redshift? I have tried this one but got an error message.
select top 10 * into #a from public.item_activity where item_act_timestamp < DATEADD(day,-1,getdate());
select * from #a
"ERROR: 42P01: relation "#a" does not exist"
Temp tables are automatically dropped at the end of the session in which it is created. Agreed with above comment, what is your use case? are you "cleaning up"? you can delete temp tables only within the current session that they are created though!
The temporary table is created in a separate, session-specific Redshift schema. However, you cannot specify a name for this schema. The schema is internal and not visible to the user. To create a temporary table, simply specify the TEMPORARY keyword (or TEMP abbreviation) in your CREATE TABLE DDL statement.
Similar to many other relational databases such as Netezza, Snowflake, Oracle, etc. Amazon Redshift support creating temp or temporary tables to hold non-permanent data. i.e. Data which you will use only in the current session and Redshift will drop the temp table soon after the session ends.
You can use UTF-8 multibyte characters up to a maximum of four bytes. Amazon Redshift enforces a quota of the number of tables per cluster by node type, including user-defined temporary tables and temporary tables created by Amazon Redshift during query processing or system maintenance.
Unlike relational databases, data in a Redshift table is stored in sorted order. The order of sort is determined by setting one or more columns in a table as the sort key. This architecture helps improve SQL query performance in Redshift. A Redshift Sort Key (SORTKEY) can be set at the column level, or at the table level.
You can use
Create temporary table tbl_name as (Select * from abc)
--OR
create temporary table tmp_date_var AS
( SELECT '2017-04-01'::Date AS stdt,'2018-01-31'::Date AS enddt);
Please create table table using command below below:
CREATE TEMP TABLE temp_table_name ....
Once this is done , use select query as below
select * from temp_table_name
The temp table exists only for duration of your session using which you have created the table.
This problem vexed me for a while as well so posting solution even though the question was asked a while ago. The solution lies in the tool you're using, Aginity in my case, there are 2 ways to solve:
If you're not using Aginity, look for a similar setting in your tool.
Hopefully, I was able to help someone with this!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With