Temporary tables
Syntax for temporary table creation is not unique across all database engines.
Not all database servers support temporary tables. The engines supporting this feature often provide it with a specific table creation statement:
Database Server Type | Native temp table creation syntax | Temp table support |
---|---|---|
IBM® Informix® |
|
Yes, native SQL feature |
Microsoft™ SQL Server |
|
Emulated, see details |
Oracle® MySQL / MariadDB |
|
Emulated, see details |
Oracle Database Server |
or, since Oracle
18c:
|
Emulated, see details |
PostgreSQL |
|
Emulated, see details |
SAP HANA® |
|
Emulated, see details |
SQLite |
|
Emulated, see details |
Dameng® |
|
Emulated, see details |
The behavior and limitations of temporary tables varies with the type of database server. See database adaptation guides for more details.
Simple Informix-style SQL statement creating temporary tables can be
converted to a native SQL equivalent instruction. However, complex SQL statements such as
SELECT .. INTO TEMP
with subqueries may fail. In such cases, create a view from
the complex query and then create the temp table from the view. Or, disable Informix emulation
and use the native SQL syntax to create the temporary table (EXECUTE IMMEDIATE "/*
fglhint_no_ifxemul */ …"
)
With Informix SQL, if the source table has a column defined as SERIAL
or
BIGSERIAL
, a SELECT ... INTO TEMP
will produce a new temp table
with an auto-incremented serial column. With the SELECT … INTO TEMP
emulation for
non-Informix databases, not using the native sequence generators (such as IDENTITY
columns in SQL Server), the resulting temporary table will get a simple INTEGER
or
BIGINT
column, instead of an auto-incremented column.
Consider reviewing programs using temporary tables, and adapt the code to create temporary tables with native SQL syntax.