ReferenceSQL ReferenceStatements

CREATE TABLE

Create a raw table with the supported engine and optional sorting key.

CREATE TABLE

This page describes statements accepted by the Query API in RawTree Cloud and RawTree BYOC. Its restrictions apply to the API, not to all RawTree SQL. See ClickHouse compatibility and API scope.

Syntax

CREATE TABLE [IF NOT EXISTS] <table>
  ENGINE = ReplicatedRawMergeTree
  [ORDER BY <expressions>]
  [SETTINGS <name> = <value> [, ...]]

CREATE TABLE requires admin permission. The table belongs to the selected database.

Clauses

ClauseMeaning
IF NOT EXISTSDo not return an error when the table exists.
ENGINEUse ReplicatedRawMergeTree.
ORDER BYSet an optional sorting-key expression.
SETTINGSSet table settings with the engine's native validation.

Query API behavior

  • Supported: The syntax shown above.
  • Not exposed by the Query API: Column definitions, engine arguments, AS SELECT, other engines, and other table clauses.
  • Query API scope: The API creates raw tables and selects the engine and database.

CREATE TABLE ... SETTINGS returns 400 on databases with custom S3 storage. Create the table without a SETTINGS clause. Some settings can only be set at creation.

Errors

Error: Unsupported CREATE TABLE statement.

Hint: The API returns the supported form with your table name.

Only CREATE TABLE [IF NOT EXISTS] <table> ENGINE = ReplicatedRawMergeTree [ORDER BY <expressions>] [SETTINGS name = value, ...] is supported. Use: CREATE TABLE my_table ENGINE = ReplicatedRawMergeTree

Examples

Create a table with an explicit sorting key.

CREATE TABLE events ENGINE = ReplicatedRawMergeTree ORDER BY (tenant, event_time)

Create a table only when it does not exist.

CREATE TABLE IF NOT EXISTS archive_events ENGINE = ReplicatedRawMergeTree