Skip to main content
Creates a new table.
CREATE TABLE Syntax

Parameters

OR REPLACE

Any existing table or view with the same name will be dropped before creating this one; mutually exclusive with IF NOT EXISTS

REPLICATED

The table will be distributed within the database as a replicated table

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 a table or view with the same name exists, do nothing; mutually exclusive with OR REPLACE

<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>

Name of the table to create; must adhere to the supported naming criteria

<column name>

Name of a column to create within the table; must adhere to the supported naming criteria

<column definition>

Definition of the column associated with <column name>; see Data Definition (DDL) for column format

COMMENT '<column comment>'

Apply column comment <column comment> to the column associated with <column name>

SOFT

Modifier for PRIMARY KEY that creates a soft primary key instead of a standard primary key

PRIMARY KEY (<column list>)

Optional primary key specification clause, where <column list> is a comma-separated list of columns to use as the primary key for the table

SHARD KEY (<column list>)

Optional shard key specification clause, where <column list> is a comma-separated list of columns to use as the shard key for the table

FOREIGN KEY ...

Optional comma-separated set of foreign key specification clauses, with the following parameters:
ParameterDescription
<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>

Defines a partitioning scheme for the table to create

<tier strategy clause>

Defines the tier strategy for the table to create

<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>

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
See Partitioning for details.

Range Partitioning

The general format for the range partition clause is:
PARTITION BY RANGE Syntax
The partition definition clause, PARTITIONS, is optional, though it is recommended to define partitions at table creation time, when feasible.
Defining (adding) partitions after data has been loaded will result in a performance penalty as the database moves existing records targeted for the new partition from the default partition into it.
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
For example, to create an interval-partitioned table with the following criteria:
  • 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
To create an interval-partitioned table with the following criteria:
  • 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
The same interval-partitioned scheme above can be created using the timestamp column directly, with the help of the INTERVAL function (described in the Date/Time Functions section):
PARTITION BY INTERVAL (Day) Alternate Syntax
This scheme can be easily modified to create an hourly partition instead:
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
The partition definition clause, PARTITIONS, is optional, though it is recommended to define partitions at table creation time, when feasible.
Defining (adding) partitions after data has been loaded will result in a performance penalty as the database moves existing records targeted for the new partition from the default partition into it.
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
To create a manual list-partitioned table with a multi-column key and the following criteria:
  • 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
To create an automatic list-partitioned table with the following criteria:
  • 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
To create a hash-partitioned table with the following criteria:
  • 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
The 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
To create a series-partitioned track table with the following criteria:
  • 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
For example, to create a customer_order table with an above-average eviction priority in the RAM Tier:
TIER STRATEGY Example
If not specified, the default tier strategy will be assigned:
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
For example, to create a table with the following indexes:
  • 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
Available table properties include:

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

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

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

The default compression type to apply to columns of this table not explicitly given one.

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

The type of primary key index to use.The default is memory.
TypeDescription
memoryPrimary key index is loaded into memory, occupying RAM but improving performance.
diskPrimary key index is stored on disk only, increasing available RAM at the cost of some performance.

TTL

The time-to-live (TTL) for the table; if not set, the table will not expire.
For example, to create a table with up to 1,000,000 records per chunk and that will expire in 15 minutes:
Table Property Example