sys.tables system catalog table.
For information on other database components, see the pages on Databases, Schemas, Views, and Indexes.
CREATE TABLE
Creates a new table in the current database. The table name must be distinct from the name of any existing tables in the database unless theREPLACE keyword is specified. To use REPLACE in the CREATE TABLE statement, you must have DELETE privileges.
By default, columns are nullable unless otherwise specified.
For faster query results, you can define one for the table, which must be a timestamp, date, or time column, with a specified bucket resolution. Tables with a specified TimeKey can perform query operations faster, especially if they involve time filtering.
You can specify a Clustering Key composed of one or more fixed-length columns. Designating columns as cluster keys that are frequently referenced in queries can greatly improve performance.
For details about defining TimeKeys and clustering indexes, see TimeKeys and Clustering Keys.
See the Data Types section for table-supported data types.
Required Privileges: You must have the CREATE TABLE privilege for the current database.
For examples, see CREATE TABLE SQL Statement Examples.
SQL
Column Definition (<column_definition>)
The parameters listed here are required for defining each column in a table.
Clustering Key and Index Definition (<clustering_definition>)
The parameters listed here are required for defining a Clustering Key or clustering indexes on a table.
For details about how to apply clustering columns, see Clustering Key.
SQL
TimeKey Definition (<timekey_definition>)
This syntax example is for a single TimeKey column, which can be included in the column definition of a CREATE TABLE statement. For the full syntax, see CREATE TABLE.
For details about using TimeKeys, see TimeKeys.
SQL
Column Constraint (<column_constraint>)
The parameters listed here include constraints and other configurations for individual columns. For best performance, one column with date or time data in each table should be defined as the TIME KEY with a specified bucket_value.
For details about TimeKey columns, see TimeKeys.
Create Option (<create_option>)
The parameters listed here include various options to configure table storage space, segments, redundancy, streamloading, and indexes.
Example
This example creates a new table in the current database and schema named
trades.
The table uses the TIMESTAMP column created_at as the TimeKey, with the granularity set at 1 hour. The columns ticker_symbol and t_type are defined as the table clustering keys. The example also includes a streamloader property pageQueryExclusionDuration to delay how soon data pages that were recently added can be included in query results.
SQL
CREATE TABLE AS SELECT (CTAS)
CTAS provides the ability to create and load a new table from the result of a query on one or more existing tables. The first column of the query result maps to the first column of the new table definition, the second column maps to the second column of the new table, and so on. The new table is available for querying after it has been created, and the entire result set from the query has been loaded into the table. When you receive a response to the CTAS SQL statement, the load is complete, and the table is ready. When you create a table from aSELECT SQL statement, the schema for the table can be automatically determined based on the query results. You can override this behavior with an alternative schema, provided the query results can automatically be cast to the target column types. CTAS also supports all syntax options for the new table. CTAS does not support default values and explicit nullable definitions on the column of the table.
CTAS statements support secondary and prefix indexes.
To create a table, you must have both the CREATE TABLE privilege for the current database and the SELECT privilege on all referenced tables and views.
For syntax and parameter information, see CREATE TABLE.
Default Table Definitions
By default, a new table created with a CTAS statement retains column names, data types, and nullable definitions from the queried table. You can override this configuration with alternate table definitions in the CTAS statement. Examples These CTAS examples select columns from theoriginal_table table that this CREATE TABLE statement defines. This table contains these columns:
col_int— Non-nullable integer with the default value123456789col_bigint— Non-nullable 8-byte signed integercol_id— Non-nullable integercol_point— Non-nullable point with the default valuePOINT(0 0)col_timestamp— Non-nullable TimeKey with granularity set at 1 daycol_varchar— Variable-length character string with a maximum length of 255 characters and Zstandard compression
ck using the col_bigint and col_id columns. It also has two secondary indexes: a hash index idx_01 on the col_varchar column and a spatial index on the idx_02 column.
SQL
original_table table.
SQL
basic_ctas table includes all the columns and data types from the original table definition. However, it does not include the segment keys, indexes, or the compression on the col_varchar column. The EXPORT TABLE SQL statement shows the differences in the basic_ctas table.
SQL
Text
REDUNDANCY, STORAGESPACE, and SEGMENTSIZE are all default table settings.
CTAS Using a Full Table Definition
This example CTAS statement includes a more detailed table definition. The definition includes new columns for the TimeKey, Clustering Key, and secondary indexes. The example also makes various changes from the original_table schema:
- Different column default value
- Different compression scheme (dynamic compression)
- New TimeKey granularity of 1 hour
- Three columns in the Clustering Key
- Different secondary index types (
NGRAMandSPATIAL)
SQL
col_int, col_bigint, and col_id, from the original table to insert into the new subset table. The example also specifies alternate table options for REDUNDANCY and SEGMENTSIZE.
SQL
Due to limitations of the JDBC API, the reported modified row count might not be accurate for tables larger than two billion rows.
col_int_multiplycolumn is the multiplication of thecol_intvalues by 10.col_month_addcolumn is the result of adding three months to eachcol_timestampcolumn value.col_yearcolumn is the extraction of the year value from eachcol_timestampcolumn value.col_substringcolumn contains the first three characters from eachcol_varcharcolumn value.
SQL
CTAS USING LOADERS
Specify one or more Loader Nodes for executing the CTAS SQL statement. If you do not use this option, the Ocient System uses all Loader Nodes that are live to execute the SQL statement. This statement is useful for managing loading operations, particularly when balancing multiple loads of different sizes and resource requirements. Alternatively, this statement can also help simplify small batch loads by sourcing the data from a single Loader Node. SyntaxFor the query to execute successfully, the specified names of the Loader Nodes must:
- Identify nodes that are live.
- Identify nodes that have the Loader role.
my_schema.my_ctas_table_2 with a clustering index named idx on the int_col column with the values in the int_col column in the table named my_schema.my_table. Use the Loader Node named stream-loader1 to execute this SQL statement.
SQL
stream-loader2 and stream-loader3.
SQL
DROP TABLE
DROP TABLE removes one or more existing tables in the current database, along with all associated views.
This action cannot be undone.
DELETE TABLE privileges for the table.
Syntax
SQL
Examples
This example drops an existing table in the current database and schema named
employees.
SQL
employees and departments.
SQL
IF EXISTS statement to convert the error to a warning. If you execute the DROP TABLE statement and only some of the tables exist while other tables are missing, the database drops the existing tables and returns warnings for each missing table.
ALTER TABLE
ALTER TABLE RENAME
ALTER TABLE RENAME renames an existing table.
Required Privileges
To rename a table, you must have the ALTER TABLE privilege for the table.
The Ocient System requires these privileges if this statement includes a change to the schema:
VIEWprivilege on the current schema of the tableVIEW TABLEandCREATE TABLEprivileges on the target schema (if the schema already exists)CREATE TABLEprivilege on the database (if the schema does not exist)
SQL
Example
This example renames an existing table in the current database and schema named
us.employees to mid_west_employees.
SQL
us.employees to north_america.employees.
SQL
ALTER TABLE RENAME COLUMN
ALTER TABLE RENAME COLUMN renames an existing column.
To rename a column, you must have the ALTER TABLE privilege for the table.
Syntax
SQL
Example
This example renames an existing column
name in the table employees in the current database and schema to first_name.
SQL
ALTER TABLE ADD COLUMN
ALTER TABLE ADD COLUMN adds a new column to the table.
To add a column, you must have the ALTER TABLE privilege for the table.
New columns must either be nullable or specify a default value.
For a defined list of column parameters, see Column Definition. For constraints, see Column Constraint.
Syntax
SQL
Examples
This example adds a BIGINT column to the
employees table in the current database and schema with the default value of 0.
SQL
SQL
ALTER TABLE ALTER COLUMN COMPRESSION
ALTER TABLE ALTER COLUMN COMPRESSION alters an existing column in the table to change its compression scheme.
Supported compression schemes are COMPRESSION NONE, COMPRESSION DYNAMIC, and COMPRESSION ZSTD.
Altering the compression setting of a column only affects compression for data loaded after you execute the SQL statement.
SQL
Examples
This example alters the compression scheme for the column
employee_name in the table employees in the current database and schema.
SQL
employee_name in the table employees in the current database and schema.
SQL
ALTER TABLE ALTER REDUNDANCY
ALTER TABLE ALTER REDUNDANCY alters the segment part redundancy for future segments of an existing table.
Note that altering a segment part redundancy setting only affects data loaded after applying the SQL statement.
SQL
Example
This example alters the
STATS part to COPY redundancy.
SQL
ALTER TABLE DROP COLUMN
ALTER TABLE DROP COLUMN drops an existing column from the table.
You cannot remove the TimeKey column and the clustering key columns from the table.
When you remove a column, the database does not remove or free any actual data.
SQL
Example
This example removes a column named
address from the table employees.
SQL
ALTER TABLE STREAMLOADER_PROPERTIES [#alter-table-streamloader_properties]
ALTER TABLE STREAMLOADER_PROPERTIES resets the table streamloader properties to the provided string. The properties string must be in valid JSON format.
The database registers streamloader changes dynamically. Therefore, you do not need to restart nodes or take other actions for the changes to take effect.
Any properties not specified in the string default to the system-wide setting.
SQL
Configuring Streamloader Properties
STREAMLOADER_PROPERTIES is a field on the table metadata that must be written as a JSON string in order to be read properly. The database can dynamically render any changes to STREAMLOADER_PROPERTIES with the ALTER TABLE SQL statement. You can set Loader Node properties for a new table as a parameter in the CREATE TABLE SQL statement. You do not need to restart the database node for the changes to take effect.
Per-Table Streamloader Properties
Example
This example sets the Loader Node properties of the table
employees to {"pageQueryExclusionDuration" : "30s"}. This means that any pages added less than 30 seconds ago are not included in query results.
SQL
ALTER TABLE DISABLE INDEX
TheALTER TABLE DISABLE INDEX statement instructs future queries not to use the specified indexes, but existing segments and new segments continue to have the index available in case you enable the index again.
All secondary indexes except for secondary clustering key indexes can be disabled. Trying to disable other types of indexes generates an error.
You can specify the index by name or UUID.
Syntax
SQL
Examples
This example disables an existing index named
current_idx on the table employees.
SQL
5c15d8de-36fa-4055-9bdc-3f1750aaeea0.
SQL
current_idx and other_idx on the table employees.
SQL
ALTER TABLE ENABLE INDEX
TheALTER TABLE ENABLE INDEX statement reverts the operation performed by the ALTER TABLE DISABLE INDEX statement.
Syntax
SQL
Examples
This example enables an existing index named
current_idx on the table employees.
SQL
5c15d8de-36fa-4055-9bdc-3f1750aaeea0.
SQL
current_idx and other_idx on the table employees.
SQL
ALTER TABLE ENABLE RETENTION POLICY AGE
ThisALTER TABLE SQL statement enacts a new retention policy on the specified table. A table can have only one retention policy. For details about retention policies, see Table Retention Policies.
Required Privileges
You must have the ALTER and DELETE privileges for the specified table.
Syntax
SQL
Example
This example creates a new retention policy for
my_table that deletes any rows older than 1 day.
SQL
ALTER TABLE DISABLE RETENTION POLICY
ThisALTER TABLE SQL statement disables a retention policy on the specified table. For details about retention policies, see Table Retention Policies.
Required Privileges
You must have the ALTER TABLE system privilege and the ALTER privilege for the specified table.
Syntax
SQL
Example
This example removes the retention policy for
my_table.
SQL
EXPORT TABLE
EXPORT TABLE shows the CREATE TABLE statement for an existing table in the current database.
To export a table, you must have the SELECT TABLE privilege for the table.
SQL
Example
This example exports an existing table in the current database and schema named
trades.
SQL
SQL

