Edward Ribbery
Edward Ribbery

Reputation: 37

Temporary tables in YugaByte DB

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

Answers (1)

Fizaa
Fizaa

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

Related Questions