ALTER TABLE ADD COLUMN
Adds a column to an existing table.Syntax
Parameters
Column constraints & default expression
Limitations
The query can only be executed under the following conditions:- Only on managed tables, external tables are not supported.
- The table must not have any dependent views.
- The default expression must contain only literals or functions
CURRENT_DATE(),LOCALTIMESTAMP(),CURRENT_TIMESTAMP(), andNOW().
ALTER TABLE DROP COLUMN
Removes a column from an existing table.Syntax
Parameters
Limitations
The query can only be executed under the following conditions:- Only on managed tables, external tables are not supported.
- The table must not have any dependent views.
- The column must not be part of the table’s primary index or partition key.
- The column must not be covered by a multi-column UNIQUE constraint. Drop the constraint first with ALTER TABLE DROP UNIQUE.
- The column must not be used by any aggregating index on the table (as a grouping key or within the index’s aggregation expressions). Drop or alter those indexes first. See DROP INDEX.
Examples
Drop a column from a table:ALTER TABLE RENAME COLUMN
Renames a column in an existing table while preserving all data.Syntax
Parameters
Limitations
The query can only be executed under the following conditions:- Only on managed tables, external tables are not supported.
- The table must not have any dependent views.
- Cannot rename to an existing column name.
- Column must exist (unless
IF EXISTSspecified).
Examples
Rename a column:ALTER TABLE MODIFY COLUMN
Changes the ordinal position of a column within a table’s schema.Syntax
Parameters
Limitations
The query can only be executed under the following conditions:- Only on managed tables, external tables are not supported.
- The table must not have any dependent views.
Examples
Move a column to be the first column in the table:ALTER TABLE DROP PARTITION
Use to delete a partition from a fact or dimension table.Syntax
Parameters
Examples
See the examples in Working with partitions.ALTER TABLE OWNER TO
Change the owner of a table. The current owner of a table can be viewed in theinformation_schema.tables view on table_owner column.
check ownership page for more info.
Syntax
Parameters
ALTER TABLE RENAME TO
Renames a table or a view.Syntax
Parameters
Examples
Rename a table:Limitations
The query can only be executed under the following conditions:- External tables are not supported.
- The table or view must not have any dependent views.
- Renaming across schemas and databases is not supported. Consider using CREATE TABLE CLONE for tables.
ALTER TABLE SET PRIMARY INDEX
Changes the primary index columns of an existing table. This operation only updates the table metadata definition without modifying existing tablets. New ingested data will use the updated primary index definition, while existing tablets retain their original structure until aVACUUM (UPGRADE=true) operation is performed, thus affecting query performance.
Syntax
Parameters
Examples
Change to a single column primary index:Limitations
The query can only be executed under the following conditions:- Only supported on FACT and DIMENSION tables. External tables are not supported.
- If your table contains older tablets that don’t have the primary index information in their metadata headers, you must run
VACUUM (UPGRADE=true)on the table before altering the primary index. - Tables with Text Indexes cannot have their primary index altered. You must drop all Text Indexes before modifying the primary index.
- All specified columns must exist in the table.
The ALTER TABLE operation only updates the table’s metadata definition. Existing data in tablets retains the original primary index structure until
VACUUM (UPGRADE=TRUE) is run.ALTER TABLE DROP PRIMARY INDEX
Removes the primary index from an existing table. This operation only updates the table metadata definition without modifying existing tablets. New ingested data will not use a primary index, while existing tablets retain their original structure until aVACUUM (UPGRADE=true) operation is performed.
Syntax
Parameters
Examples
Remove the primary index:Limitations
The query can only be executed under the following conditions:- Only supported on FACT and DIMENSION tables. External tables are not supported.
- If your table contains older tablets that don’t have the primary index information in their metadata headers, you must run
VACUUM (UPGRADE=true)on the table before dropping the primary index. - Tables with Text Indexes cannot have their primary index altered. You must drop all Text Indexes before dropping the primary index.
The ALTER TABLE operation only updates the table’s metadata definition. Existing data in tablets retains the original primary index structure until
VACUUM (UPGRADE=TRUE) is run.ALTER TABLE ADD STATISTICS
Add accitional [automated column statistics][acs] to collect for a column.Syntax
Parameters
Examples
Collect the number of distinct values (NDISTINCT) for the column customer_id:
customer_id:
ALTER TABLE ALTER COLUMN SET UNIQUE
Adds a UNIQUE constraint to an existing column to indicate your intent for the column’s values to be unique. Firebolt does not validate existing data or enforce uniqueness for future writes.Syntax
Parameters
Examples
Add a unique constraint to a column:Limitations
The query can only be executed under the following conditions:- Only supported on FACT and DIMENSION tables. External tables are not supported.
- The specified column must exist in the table.
- Cannot modify inner struct type fields
ALTER TABLE ALTER COLUMN DROP UNIQUE
Removes the UNIQUE constraint from an existing column. This updates the table metadata to remove the uniqueness declaration.Syntax
Parameters
Examples
Remove a unique constraint from a column:Limitations
The query can only be executed under the following conditions:- Only supported on FACT and DIMENSION tables. External tables are not supported.
- The specified column must exist in the table.
- Cannot modify inner struct type fields
ALTER TABLE ADD UNIQUE
Adds a UNIQUE constraint over one or more columns of an existing table. A multi-column constraint declares that the combination of values in the covered columns is unique across all rows. Firebolt does not validate existing data or enforce uniqueness for future writes; the constraint provides metadata to the query optimizer. See UNIQUE constraints as query hints. A single-columnADD UNIQUE (a) is equivalent to ALTER COLUMN a SET UNIQUE and is stored as a column-level constraint.
Syntax
Parameters
Examples
Declare the combination ofdevice_id and event_time unique:
STRUCT column, declaring the combination of all the struct’s fields unique:
Limitations
The query can only be executed under the following conditions:- Only supported on FACT and DIMENSION tables. External tables are not supported.
- All specified columns must exist in the table, and a column may appear only once per constraint.
- An identical constraint must not already exist on the table. Constraints are compared by their column set, so
UNIQUE (a, b)andUNIQUE (b, a)are the same constraint.
ALTER TABLE DROP UNIQUE
Removes the UNIQUE constraint over the given columns from an existing table. The constraint is matched by its column set, so the column order does not matter. A single-columnDROP UNIQUE (a) is equivalent to ALTER COLUMN a DROP UNIQUE and also removes a constraint declared on the column itself.
Syntax
Parameters
Examples
Remove the constraint overdevice_id and event_time:
Limitations
The query can only be executed under the following conditions:- Only supported on FACT and DIMENSION tables. External tables are not supported.
- All specified columns must exist in the table.
- A UNIQUE constraint over exactly the given columns must exist on the table.