Create a global temporary table

Use the following commands to create and identify global temporary tables:

To create a global temporary table:

create global temp table <table name> (colname datatype)

create global temp table <table name> as select * from <table name>

To identify a global temporary table in the database, use \d, and verify the value for Type:
  • If GLOBAL is specified, then a global temporary table is defined.
  • If LOCAL is specified, then a local temporary table is defined.
  • If TEMP is specified, then a local temporary table is defined.
GTT.ADMIN(ADMIN)=> \d

List of relations

Schema | Name |       Type       | Owner
-------+------+------------------+-------
ADMIN  | GT1  | GLOBAL TEMP TABLE| ADMIN

(1 row)
Restrictions:
  • Similarly to local temporary tables, ADD and DROP of columns are not allowed on global temporary tables.
  • User can't load data in a global temporary table using nzload.
  • Global Temporary Tables (GTT) cannot be altered once created.
  • GTT with constraints can not be restored and may result nzrestore failure with following error:
    Operation not allowed on a Global Temp Table Template.