Temporary tables
A temporary table belongs to one logical connection and lives in its temp namespace. It is useful for staging data or reusing intermediate rows within that connection.
Syntax
text
CREATE TEMP TABLE name (column type, ...)
CREATE TEMPORARY TABLE name (column type, ...)A temporary table shadows a table of the same unqualified name in main. Qualify the source as main.name or temp.name when both exist.
A native client connection retains its temporary tables. HTTP requests use separate sessions, so create and use a temporary table in the same HTTP request.
Example
Main and temporary tables with the same name
sql
CREATE TABLE staging(id UInt8);
INSERT INTO main.staging VALUES (1);
CREATE TEMP TABLE staging(id UInt8);
INSERT INTO temp.staging VALUES (7);sql
SELECT id FROM staging
FORMAT csv;text
7sql
SELECT id FROM main.staging
FORMAT csv;text
1DROP TABLE temp.staging removes the temporary table explicitly. Its rows are not a persistent staging area across connections.