Creating a table from a query
CREATE TABLE can specify an AS
clause to create a table from query results, as in the following example:
Labeling the AS clause
You can embed a LABEL hint in an AS
clause in two places:
-
Immediately after the
AS
keyword: -
In the
SELECT
statement:
If the AS clause contains labels in both places, the first label has precedence.
Labels are invalid for external tables.
Loading historical data
You can specify that the query return historical data by adding AT
followed by one of:
-
EPOCH LATEST
: Return data up to but not including the current epoch. The result set includes data from the latest committed DML transaction. -
EPOCH
integer
: Return data up to and including the specified epoch. -
TIME '
timestamp
'
: Return data from the epoch at the specified timestamp.
These options are ignored if used to query temporary or external tables.
See Epochs for additional information about how Vertica uses epochs.
Zero-width column handling
If the query returns a column with zero width, Vertica automatically converts it to a VARCHAR(80)
column. For example:
Requirements and restrictions
-
If you create a temporary table from a query, you must specify
ON COMMIT PRESERVE ROWS
in order to load the result set into the table. Otherwise, Vertica creates an empty table. -
If the query output has expressions other than simple columns, such as constants or functions, you must specify an alias for each expression, or list all columns in the column name list.
-
You cannot use
CREATE TABLE AS SELECT
with aSELECT
that returns values of complex types. You can, however, useCREATE TABLE LIKE
.