Why are there two different methods to create a temporary table in Redshift?

Viewed 44

In Redshift I can create a temporary table in two different ways.

Using the TEMPORARY parameter:

CREATE TEMPORARY TABLE tbl...

or by putting a hash at the start of the table name:

CREATE TABLE #tbl...

The Redshift docs have a special red Important box which describes this other method:

If you specify a table name that begins with '#', the table is created as a temporary table.

But they don't say why these two methods exist, and whether one is preferred over the other for any reason.

I assume the #tbl formulation is for historical/backwards compatibility reasons, but it'd be interesting to see what these are.

1 Answers

The '#' syntax for temp tables is used in several other databases (SQL server, MySQL). Redshift allows this syntax to enable greater tool compatibility and SQL portability.

Here's SQL Server's documentation for temporary tables:

Prefix local temporary table names with single number sign (#table_name), and prefix global temporary table names with a double number sign (##table_name).

Related