CREATE TABLE
Creates a table in the logical schema. For information about creating temporary tables and external tables, see CREATE TEMPORARY TABLE
and CREATE EXTERNAL TABLE AS COPY
, respectively.
Syntax
CREATE TABLE [ IF NOT EXISTS ] [schema.]table-name ... ( column‑definition[,... ] ) ... [ table-constraint ] ... [ load-method ] ... [ ORDER BY table-column[,... ] ] ... [ segmentation‑spec ] ... [ KSAFE [k‑num] ] ... [ PARTITION BY partition-expression] ... [ {INCLUDE | EXCLUDE} [SCHEMA] PRIVILEGES ]
CREATE TABLE [ IF NOT EXISTS ] [schema.]table-name { AS‑clause | LIKE‑clause }
... [ ( column-name-list ) ] ... [ load-method ] ... [ {INCLUDE | EXCLUDE} [SCHEMA] PRIVILEGES ] AS [ /*+ hint[, hint] */ ] [ AT epoch ] query [ ENCODED BY column‑ref‑list ]
LIKE [schema.]existing-table ...[ {INCLUDING | EXCLUDING} PROJECTIONS ] ...[ load-method ] ...[ {INCLUDE | EXCLUDE} [SCHEMA] PRIVILEGES ]
Parameters
IF NOT EXISTS
|
Specifies to generate an informational message if an object already exists under the specified name. If you omit this option and the object exists, Vertica generates a The For related information, see |
schema
|
Specifies a schema. If multiple schemas are defined in the database, include the schema name. For example: myschema.thisDbObject If you do not specify a schema, the table is created in the default schema. |
table-name
|
Identifies the name of the table to create, where table-name conforms to conventions described in Identifiers. |
column-definition
|
Defines a table column. A table can have up to 1600 columns. |
table‑constraint
|
Adds a constraint to table metadata. |
load-method |
Specifies default load behavior for all DML operations on this table, such as
For details, see Choosing a Load Method in the Administrator's Guide. |
ORDER BY table‑column[,...]
|
Specifies columns from the If you omit the This option is invalid for external tables. |
segmentation‑spec |
Invalid for external tables, specifies how to distribute data for auto-projections of this table. Supply one of the following clauses:
If this clause is omitted, Vertica generates auto-projections with default hash segmentation. |
KSAFE [k‑num]
|
Specifies K-safety of auto-projections created for this table, where k-num must be equal to or greater than system K-safety. If you omit this option, the projection uses the system K-safety level. For general information, see K-Safety in Vertica Concepts. Note: This option is invalid for external tables. |
PARTITION BY partition‑expression
|
Logically divides table data storage, where partition‑expression resolves to a value derived from one or more table columns. For details, see Partition Clause. This option is invalid for external tables. |
column‑name‑list
|
Valid only when creating a table from a query ( For example: CREATE TABLE customer_occupations (name, profession) AS SELECT customer_name, occupation FROM customer_dimension; This clause and the |
{ INCLUDE
|
Specifies default inheritance of schema privileges for this table:
For more information see Grant Inherited Privileges. |
AS query
|
Creates and loads a table from the results of a query, specified as follows: AS [ /*+hint[, hint]*/ ] [ AT epoch ] query You can qualify the
For details, see Creating a Table from a Query in the Administrator's Guide. |
ENCODED BY column‑ref‑list |
A list of columns from the source table, where each column is qualified by one or both of the following encoding options:
This option and column-name-list are mutually exclusive. This option is invalid for external tables |
LIKE existing-table
|
Creates the table by replicating an existing table. You can qualify the
For details, see Replicating a Table in the Administrator's Guide. |
Privileges
The following privileges are required:
CREATE
privileges on the table schema-
If creating a table that includes a named sequence:
SELECT
privilege on sequence objectUSAGE
privilege on sequence schema
- If creating a table with the
LIKE
clause, owner privileges on the source table
Examples
See Creating Tables in the Administrator's Guide.