Skip to main content
Creates a new table from the given query in the specified schema.
CREATE TABLE ... AS Syntax
The parentheses around <select statement> are optional.
Any column aliases used must adhere to the supported naming criteria. While primary keys & foreign keys are not transferred to the new table, shard keys will be, if the column(s) composing them are part of the SELECT list.

Parameters

The following can be applied to <select statement> to affect the resulting table:

Table Property Clause

A subset of table properties can be applied to the created table at creation time. The Table Property Clause syntax is the same as that in the CREATE TABLE Table Property Clause, and the USING keyword is optional in either. Of the properties available there, only CHUNK SIZE, COMPRESSION_CODEC, & TTL take effect here; any other is accepted without error and then discarded.

Examples

To create a replicated temporary table that is a copy of an existing table, failing if a table with the same name as the target table already exists:
CREATE TABLE ... AS (Replicated/Temporary) Example
To create a permanent table with columns a, b, c, & d a new shard key on columns a & b, and an index on column d, replacing a table with the same name as the target table, if it exists:
CREATE TABLE ... AS (Reshard) Example
To copy a table with columns a, b, c, & d, preserving the primary key on a, b, & c, and the foreign key from d; a new table must be created to match the schema of the old one and then records can be copied from the old one to the new one:
CREATE TABLE (Preserve Primary Key) Example, DDL Step
CREATE TABLE (Preserve Primary Key) Example, DML Step
This create/insert process is necessary, as neither primary keys nor foreign keys can be preserved through hints.
See Limitations for other restrictions.