Variables in SQL Runner


Hi Snowplowers,

Can we use variable in SQL Runner. We are doing some clean up activity and we want to log some information, thus want to use variable.

Deepak Bhatt


Hi @deepak,

Do you mean populating your SQL via variables?

We have options to template noted here:

You can pass in variables to use in the template from:

These variables can then be referenced in the SQL like so:

Hope this helps,



Hi @josh

Appreciate your quick reply. But I want to store the result of my previous query in some variable and insert the same variable into table. Is this possible.

Deepak Bhatt


Hi @deepak,

That’s not possible at the moment. You can store the result in a temporary table though (not as clean a solution, but it works).


Hi @christophe

I want to do the same but I am not able to achieve it i.e. I want to store some audit data into an temp table but I am not able to find a way how can I store the result of previous query into temp table.Can you please share some sample query, which I can follow.
Appreciate your help.

Deepak Bhatt


To create a temporary table (that is destroyed at the end of the session) you can do something similar to:

CREATE TEMPORARY TABLE example AS (select 1)

Where example is the name of your temporary table and the select 1 statement is the query that should populate the table with the given data. The AWS documentation has more detail about CTAS statements here.


Hi @mike

Thanks for your quick reply.

What I want: I want to cleanup my redshift DB and want to audit the data. For that I will create an temp table in which I will insert precount, deleted records, post count, table name & date. So I want a way to insert records with the previous result.

Deepak Bhatt