<column list> is a
comma-separated list of columns to use as the primary key for the tableCREATE TABLE Syntax
Parameters
OR REPLACE
OR REPLACE
Any existing table or view with the same name will be dropped before creating this one;
mutually exclusive with
IF NOT EXISTSREPLICATED
REPLICATED
The table will be distributed within the database as a replicated
table
TEMP
TEMP
The table will be a memory-only table; which, among
other things, means it will not be persisted (if the database is restarted, the table will be
removed), but it will have increased ingest performance
IF NOT EXISTS
IF NOT EXISTS
If a table or view with the same name exists, do nothing; mutually exclusive with
OR REPLACE<schema name>
<schema name>
Name of the schema that will contain the created table; if no schema is specified, the
table will be created in the user’s default schema
<table name>
<table name>
Name of the table to create; must adhere to the supported
naming criteria
<column name>
<column name>
Name of a column to create within the table; must adhere to the supported
naming criteria
<column definition>
<column definition>
Definition of the column associated with
<column name>; see Data Definition (DDL) for column
formatCOMMENT '<column comment>'
COMMENT '<column comment>'
SOFT
SOFT
Modifier for
PRIMARY KEY that creates a soft primary key instead
of a standard primary keyPRIMARY KEY (<column list>)
PRIMARY KEY (<column list>)
Optional primary key specification clause, where
FOREIGN KEY ...
FOREIGN KEY ...
Optional comma-separated set of foreign key specification clauses, with
the following parameters:
| Parameter | Description |
|---|---|
<column list> | Comma-separated list of columns in the table to create that will reference a matching set of primary key columns in another table |
<foreign table name> | Name of target table referred to in this foreign key |
<foreign column list> | The primary key columns in the target table referred to in this foreign key, matching the list of columns specified in <column list> in the table to create |
AS <foreign key name> | Optional alias for the foreign key |
<partition clause>
<partition clause>
Defines a partitioning scheme for the table to create
<tier strategy clause>
<tier strategy clause>
Defines the tier strategy for the table to create
<index clause>
<index clause>
Applies any number of column indexes,
chunk skip indexes,
geospatial indexes,
CAGRA indexes, or
HNSW indexes
to the table to create
<table property clause>
<table property clause>
Assigns table properties, from a subset of those available, to the table to create
Examples
To create a table with various column types and properties:CREATE TABLE Example
Partition Clause
A table can be further segmented into partitions. The supported partition types are:Range
Partition by defined value ranges to improve filter & join performance
Interval
Partition by numeric or time-based intervals with dynamic partition creation
List
Partition by discrete sets of values to improve filter performance
Hash
Partition by hash of key columns to improve equi-join performance
Series
Partition into a sequence of dynamically-allocated partitions, filling each to a threshold
Range Partitioning
The general format for the range partition clause is:PARTITION BY RANGE Syntax
PARTITIONS, is optional, though it is
recommended to define partitions at table creation time, when feasible.
For example, to create a range-partitioned table with the following
criteria:
- partitioned on the date/time of the order
-
partitions for years:
- 2014 - 2016
- 2017
- 2018
- 2019
- records not in that range go to the default partition
PARTITION BY RANGE Example
Interval Partitioning
The general format for the interval partition clause is:PARTITION BY INTERVAL Syntax
- partitioned on the date/time of the order
- one partition for each year from 2014 on
- later year partitions are added as necessary
- records prior to 2014 go to the default partition
PARTITION BY INTERVAL (Year) Syntax
- partitioned on the date/time of the order
- one partition for each day from January 1st, 2014 on
- later day partitions are added as necessary
- records prior to 2014 go to the default partition
PARTITION BY INTERVAL (Day) Syntax
INTERVAL function
(described in the Date/Time Functions section):
PARTITION BY INTERVAL (Day) Alternate Syntax
PARTITION BY INTERVAL (Hour) Syntax
List Partitioning
The list partition clause has two forms:manual
Define partitions as specific value lists; unmatched records go to the default partition
automatic
Database automatically creates a partition for each distinct partition key value
Manual
The general format for the manual list partition clause is:PARTITION BY LIST Syntax
PARTITIONS, is optional, though it is
recommended to define partitions at table creation time, when feasible.
For example, to create a manual list-partitioned table with the following
criteria:
- partitioned on the date/time of the order
-
partitions for years:
- 2014 - 2016
- 2017
- 2018
- 2019
- records not in that list go to the default partition
PARTITION BY LIST (Year) Example
- partitioned on the date/time of the order
- each partition corresponds to a unique year & month pair
-
partitions for years/months:
- February 2016 & March 2016
- March 2020
- records not in that list go to the default partition
PARTITION BY LIST (Month) Example
Automatic
The general format for the automatic list partition clause is:Automatic PARTITION BY LIST Syntax
- partitioned on the date/time of the order
- one partition for each unique year & month across all orders
- partitions are added as necessary
Automatic PARTITION BY LIST (Month) Example
Hash Partitioning
The general format for the hash partition clause is:PARTITION BY HASH Syntax
- partitioned on the date/time of the order
- distributed among the fixed set of partitions, based on the hash of the year & month of the order
- 10 partitions
PARTITION BY HASH Example
Series Partitioning
The general format for the series partition clause is:PARTITION BY SERIES
PERCENT_FULL should be an integer between 1 and 100; the default is
50%.
To create a series-partitioned table with the following criteria:
- partitioned on the customer of each order
- partitions with closed key sets will contain all orders from a set of unique customers
- 50% fill threshold
PARTITION BY SERIES Example
- partitioned on the track ID
- partitions with closed key sets will contain all points from a unique set of tracks
- 25% fill threshold
PARTITION BY SERIES (Tracks) Example
Tier Strategy Clause
A table can have a tier strategy specified at creation time. If not assigned a tier strategy upon creation, a default tier strategy will be assigned.TIER STRATEGY Clause Syntax
customer_order table with an above-average
eviction priority in the
RAM Tier:
TIER STRATEGY Example
Default TIER STRATEGY Example
SHOW TABLE Command to Display TIER STRATEGY
SHOW TABLE Command Output
The response to
SHOW TABLE is a single-record result set
with the DDL statement as the value in the DDL column, shown here with
the column separators returned by kisql.Index Clause
A table can have any number of indexes applied to any of its columns at creation time. The types of explicit indexes supported are:Column (Attribute) Index
B-tree index on a column for equality and range filter performance
Low Cardinality Index
Column index optimized for columns with many duplicate values, using less memory
Chunk Skip Index
Improves equality-based filtering, especially on partition key columns
Geospatial Index
Improves performance of geospatial functions on geometry columns
CAGRA Index
GPU-accelerated graph-based index for vector similarity search; requires manual refresh
HNSW Index
Graph-based index for vector similarity search; automatically maintained
Index Clause Syntax
- column index on
last_name - low-cardinality index on
dept_id - chunk skip index on
id - geospatial index on
work_district - geospatial index on the pair of
office_longitude&office_latitude - CAGRA index on
profile
Index Example
Table Property Clause
A subset of table properties can be applied to the table at creation time.Table Property Clause
CHUNK COLUMN MEMORY
CHUNK COLUMN MEMORY
Size of the blocks of memory holding the data, when loaded; specified as the
maximum number of bytes any one column should hold.
The size of dictionary-encoded columns is estimated.
CHUNK MEMORY
CHUNK MEMORY
Size of the blocks of memory holding the data, when loaded; specified as the
maximum total number of bytes all columns should hold.
The size of dictionary-encoded columns is estimated.
CHUNK SIZE
CHUNK SIZE
Size of the blocks of memory holding the data, when loaded; specified as the
maximum number of records each block of memory should hold.
COMPRESSION_CODEC
COMPRESSION_CODEC
The default compression type to apply
to columns of this table not explicitly given one.
NO_ERROR_IF_EXISTS
NO_ERROR_IF_EXISTS
Error suppression option, which causes no error to be returned if a table
with the same name already exists; default is
FALSE.This is the same option as
IF NOT EXISTS.PRIMARY_KEY_TYPE
PRIMARY_KEY_TYPE
The type of primary key index to use.The default is
memory.| Type | Description |
|---|---|
memory | Primary key index is loaded into memory, occupying RAM but improving performance. |
disk | Primary key index is stored on disk only, increasing available RAM at the cost of some performance. |
TTL
TTL
The time-to-live (TTL) for the table; if not set,
the table will not expire.
Table Property Example
<column comment>to the column associated with<column name>