Reputation: 37
The idea of temporary tables is present in many databases. Are there any plans to support temporary tables in YugaByte DB SQL clusters?
Upvotes: 1
Views: 272
Reputation: 96
Temporary tables are supported in YSQL since release v1.2.4 (https://docs.yugabyte.com/latest/releases/).
You can create a temporary table using the syntax CREATE TEMP TABLE table_name ...
. A temporary table in YSQL is only visible to the session that created it, and is dropped when that session terminates.
You can alter the behavior of temporary tables at the end of a transaction block in
YSQL using the ON COMMIT
clause. The available options are PRESERVE ROWS
(this is done by default), DELETE ROWS
, and DROP
.
An example:
CREATE TEMP TABLE test (number int) ON COMMIT DELETE ROWS;
BEGIN;
INSERT INTO test VALUES (1);
COMMIT; -- all rows in test are deleted on commit
SELECT * FROM test;
number
--------
(0 rows)
Upvotes: 5