Global Temporary Tables (GTT)
Global temporary tables have persistent metadata, but their contents are transaction-bound (the default) or connection-bound.Every transaction or connection has its own private instance of a GTT, isolated from all the others.Instances are only created if and when the GTT is referenced.They are destroyed when the transaction ends or on disconnect.The metadata of a GTT can be modified or removed using ALTER TABLE
and DROP TABLE
, respectively.
CREATE GLOBAL TEMPORARY TABLE tablename (<column_def> [, {<column_def> | <table_constraint>} ...]) [<gtt_table_attrs>] <gtt_table_attrs> ::= <gtt_table_attr> [gtt_table_attr> ...] <gtt_table_attr> ::= <sql_security> | ON COMMIT {DELETE | PRESERVE} ROWS
Note
|
Syntax notes
|
GTTs are writable in read-only transactions.The effect is as follows:
- Read-only transaction in read-write database
-
Writable in both
ON COMMIT PRESERVE ROWS
andON COMMIT DELETE ROWS
- Read-only transaction in read-only database
-
Writable in
ON COMMIT DELETE ROWS
only