Book Contents

Book Index

Next Topic

Home

CREATE TEMPORARY TABLE

Creates a table and a corresponding superprojection consisting of persistent metadata and temporary data (materialized only until the current transaction ends). Data stored in a temporary table exists only in memory and is never written to disk.

The purpose of a temporary table is to perform complex queries in multiple steps: first get a result set, then query the result set, and so forth.

Syntax

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ]

TABLE table-name (

{ column-name data-type

[ DEFAULT default ]

[ NULL | NOT NULL ]

} ...

)

[ NO PROJECTION ]

[ ON COMMIT { DELETE ROWS | PRESERVE ROWS } ]

Semantics

 

GLOBAL

LOCAL

are ignored; temporary tables are always global (visible to all database users).

table-name

specifies the name of the temporary table to be created.

column-name

specifies the name of a column to be created in the new temporary table.

data-type

specifies one of the supported data types:

BOOLEAN

CHARACTER

CHARACTER VARYING

Date/Time Types

DOUBLE PRECISION (FLOAT8)

INTEGER AND BIGINT

DEFAULT default

assigns a default data value to be used in any INSERT operation that does not specify a value for the column. The data type of the default expression must match the data type of the column. If no default value is specified, the default is null.

NULL

(default) specifies that the column is allowed to contain null values.

NOT NULL

specifies that the column must receive a value during INSERT and UPDATE operations. If no DEFAULT value is specified and no value is provided, the INSERT or UPDATE statement returns an error because no default value exists.

NO PROJECTION

prevents the automatic creation of a superprojection for the temporary table using a default algorithm to choose sort order and compression.

DELETE ROWS

PRESERVE ROWS

is ignored; rows are always deleted on commit.

Notes