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
Generated columns
A generated column’s value is always the expression it is declared with, recomputed from the row’s other columns on every write:SELECT * and in information_schema.columns, and it can be used in PRIMARY INDEX and PARTITION BY. information_schema.columns reports it with is_generated = 'ALWAYS' and the expression in generation_expression.
No value may be assigned to a generated column, so INSERT and UPDATE cannot target one. A generated column still occupies a position in the table’s column order, which means an INSERT without a column list must supply values only up to the first generated column:
STORED means the value is materialized on disk. It is mandatory: GENERATED ALWAYS AS (<expression>) on its own is a syntax error. VIRTUAL generated columns are not supported.
The defining expression must be deterministic. It cannot reference the column it defines, another generated column, or a TIMESTAMPTZ column, and it cannot contain aggregates, window functions, subqueries or user-defined functions. The column’s declared type wins: the expression is cast to it. A generated column may be declared NOT NULL, in which case a row whose expression evaluates to NULL is rejected when it is written.
A generated column may be of any type, STRUCT and ARRAY included. A STRUCT column is generated as a whole: the clause is declared once for the column and cannot be declared on an individual STRUCT field.
Generated columns are supported on fact and dimension tables only. A generated column cannot be added to an existing table with ALTER TABLE ADD COLUMN, and a column referenced by one cannot be dropped.
Table-level UNIQUE constraints
AUNIQUE constraint over one or more columns can also be declared as a separate element of the column list:
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
AFOREIGN KEY declares that the listed columns reference a unique key of another table:
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.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
NULLinsert – a direct insertion of aNULLvalue into a particular column. - An Implicit
NULLinsert – anINSERTstatement with missing values for a particular column.
t1 with five columns, specifying if each column can contain NULL values, their default values, and a primary index on col2:
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:PRIMARY INDEX
ThePRIMARY 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
PARTITION BY
ThePARTITION 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.
PARTITION BY expressions:
- TO_YYYYMM
- TO_YYYYMMDD
- EXTRACT
(year|month|day|hour from <column_name>) - DATE_TRUNC
Table type
Firebolt supports two types of tables:FACTtable - the data is distributed across all nodes of the engine.DIMENSIONtable - the entire table is replicated in every node of the engine.
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 optionalWITH (...) 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.Related functions
Firebolt also supports the following related functions:- CREATE TABLE AS SELECT (CTAS) – - Creates a table and loads data into it based on a
SELECTquery. - CREATE TABLE CLONE – Creates a table that is a copy of an existing table in the database.