INTO TABLE Clause
Creates a table from a query result set.
Syntax
INTO [TABLE] [[database.]schema.]table
INTO [scope] TEMP[ORARY] [TABLE] [[database.]schema.]table ... [ ON COMMIT { PRESERVE | DELETE } ROWS ]
Parameters
scope |
Specifies visibility of a temporary table definition:
Regardless of this setting, retention of temporary table data is set by the keywords For more information, see Creating Temporary Tables in the Administrator's Guide. |
[database.]schema
|
Specifies a schema, by default myschema.thisDbObject If you specify a database, it must be the current database. |
table |
The name of the table to create. |
ON COMMIT { PRESERVE | DELETE } ROWS
|
Specifies whether data is transaction- or session-scoped:
|
Examples
The following SELECT
statement has an INTO TABLE
clause that creates table newTable
from customer_dimension
:
=> SELECT * INTO TABLE newTable FROM customer_dimension;
The following SELECT
statement creates temporary table newTempTable
. By default, temporary tables are created at a global scope, so its definition is visible to other sessions and persists until it is explicitly dropped. No customer_dimension
data is copied into the new table, and Vertica issues a warning accordingly:
=> SELECT * INTO TEMP TABLE newTempTable FROM customer_dimension; WARNING 4102: No rows are inserted into table "public"."newTempTable" because ON COMMIT DELETE ROWS is the default for create temporary table HINT: Use "ON COMMIT PRESERVE ROWS" to preserve the data in temporary table CREATE TABLE
The following SELECT
statement creates local temporary table newTempTableLocal
. This table is visible only to the session in which it was created, and is automatically dropped when the session ends. The INTO TABLE
clause includes ON COMMIT PRESERVE ROWS
, so Vertica copies all selection data into the new table:
=> SELECT * INTO LOCAL TEMP TABLE newTempTableLocal ON COMMIT PRESERVE ROWS FROM customer_dimension; CREATE TABLE