Skip to main content
Creates a new table in the current database.

Syntax

Parameters

All identifiers are case-insensitive unless enclosed in double-quotes. For more information, see Object identifiers.

Column constraints and the default expression

Firebolt supports the following column constraints:
Only literals and the following functions are supported in default expressions: CURRENT_DATE, LOCALTIMESTAMP, CURRENT_TIMESTAMP, and NOW, which is an alias for CURRENT_TIMESTAMP.
STRUCT fields within ARRAY columns cannot have UNIQUE constraints

Table-level UNIQUE constraints

A UNIQUE constraint over one or more columns can also be declared as a separate element of the column list:
A multi-column constraint declares that the combination of values in the covered columns is unique across all rows. A single-column UNIQUE (a) is equivalent to declaring UNIQUE on the column itself and is stored as such. A constraint may cover a STRUCT column, declaring the combination of all the struct’s fields unique. Like the column-level constraint, table-level constraints are not enforced; they provide metadata to the query optimizer. See UNIQUE constraints as query hints. Constraints can be added to and removed from an existing table with ALTER TABLE ADD UNIQUE and ALTER TABLE DROP UNIQUE.

Table-level FOREIGN KEY constraints

A FOREIGN KEY declares that the listed columns reference a unique key of another table:
The referencing and referenced column lists must have the same length and matching column types, and the referenced columns must be a unique key of the referenced table: either a single column declared UNIQUE, or the full set of columns of a table-level UNIQUE constraint. The referenced table must be in the same database. NOT ENFORCED is required. Firebolt stores the foreign key as query-optimizer metadata and never verifies that the referencing values exist in the referenced table, so preserving referential integrity is the user’s responsibility.
Creating a FOREIGN KEY requires the SELECT privilege on the referenced table. The constraint reads the referenced table’s schema, and it restricts later DDL on that table: a referenced column, or the UNIQUE key it relies on, cannot be dropped while an inbound foreign key exists. Requiring SELECT prevents a user from placing a constraint on, and thereby affecting the DDL of, a table they cannot read. Without SELECT on the referenced table, the CREATE TABLE statement is rejected.
The following example creates a fact table with a foreign key onto the UNIQUE key of a dimension table:

Example: Creating a table with NULL and NOT NULL values

The following example illustrates different use cases for column definitions and INSERT statements:
  • An Explicit NULL insert – a direct insertion of a NULL value into a particular column.
  • An Implicit NULL insert – an INSERT statement with missing values for a particular column.
The following example creates a fact table t1 with five columns, specifying if each column can contain NULL values, their default values, and a primary index on col2:
After creating a table, you can manipulate the values using different INSERT statements, as shown in the following examples:

Example creating table with UNIQUE constraint over columns

The following examples illustrates UNIQUE constraint over different column definitions : Primitive types:
Multi-column constraints:
STRUCT fields and columns:
ARRAY columns:

PRIMARY INDEX

The PRIMARY INDEX is an optional sparse index that sorts and organizes data based on the indexed field as it is ingested, without affecting data scan performance. For more information, see Primary index.

Syntax

The following table describes the primary index parameters:

PARTITION BY

The PARTITION BY clause defines one or more columns that determine how the table is divided into physical parts. These columns serve as the partition key and cannot allow NULL values. When multiple columns are used as the partition key, the combination of all of these columns define the partition boundaries.
The following subset of SQL functions can be used in PARTITION BY expressions: For more information, see Working with partitions.

Table type

Firebolt supports two types of tables:
  • FACT table - the data is distributed across all nodes of the engine.
  • DIMENSION table - the entire table is replicated in every node of the engine.
The CREATE TABLE command defaults to a FACT table. DIMENSION tables are ideal for relatively small tables, up to tens of gigabytes, that are used in joins with FACT tables.

Storage Parameters

Storage parameters are specified in the optional WITH (...) clause as comma separated <storage_parameter> = <storage_parameter_value> assignments. All identifiers are case-insensitive unless enclosed in double-quotes. For more information, see Object identifiers.

DESCRIPTION

It is possible to add a description to the table as well as to the columns during the table creation.
Firebolt also supports the following related functions: