CREATE TABLE command to create a new table. Tables consist of fixed columns and insertable rows. Rows can be added using the
INSERT command. When creating a table, you can specify connector settings and data format.
If you choose not to persist the data from the source in RisingWave, use
CREATE SOURCE instead.
CREATE TABLE [ IF NOT EXISTS ] table_name (
col_name data_type [ PRIMARY KEY ] [ DEFAULT default_expr ] [ AS generation_expression ],
[ PRIMARY KEY (col_name, ... ) ]
[ watermark_clause ]
[ APPEND ONLY ]
[ WITH (
[FORMAT data_format ENCODE data_encode [ (
schema.location='location', ...) ]
For tables with primary key constraints, if you insert a new data record with an existing key, the new record will overwrite the existing record.
A generated column that is defined with non-deterministic functions cannot be specified as part of the primary key. For example, if
A1 is defined as
current_timestamp(), then it cannot be part of the primary key.
Names and unquoted identifiers are case-insensitive. Therefore, you must double-quote any of these fields for them to be case-sensitive.
The syntax for creating a table with connector settings and the supported connectors are the same as for creating a source. See
CREATE SOURCE for a full list of supported connectors and data formats.
To know when a data record is loaded to RisingWave, you can define a column that is generated based on the processing time (
<column_name> timestampz AS proctime()) when creating the table or source.
|Parameter or clause||Description|
|The name of the table. If a schema name is given (for example, |
|The name of a column.|
|The data type of a column. With the |
|The expression for the generated column. For details about generated columns, see Generated columns.|
|A clause that defines the watermark for a timestamp column. The syntax is |
|When this option is specified, the table will be created as an append-only table. An append-only table cannot have primary keys. |
|WITH clause||Specify the connector settings here if trying to store all the source data. See the Data ingestion page for the full list of supported source as well as links to specific connector pages detailing the syntax for each source.|
|FORMAT and ENCODE options||Specify the data format and the encoding format of the source data. To learn about the supported data formats, see Data formats.|
RisingWave supports generating watermarks when creating an append-only streaming table. Watermarks are like markers or signals that track the progress of event time, allowing you to process events within their corresponding time windows. For more information on the syntax on how to create a watermark, see Watermarks.
The statement below creates a table that has three columns.
CREATE TABLE taxi_trips(
distance DOUBLE PRECISION,
The statement below creates a table that includes nested tables.
CREATE TABLE IF NOT EXISTS taxi_trips(
distance DOUBLE PRECISION,
duration DOUBLE PRECISION,
initial_charge DOUBLE PRECISION,
subsequent_charge DOUBLE PRECISION,
surcharge DOUBLE PRECISION,
tolls DOUBLE PRECISION>);
The statement below creates a table with a Kafka broker as the source.
CREATE TABLE IF NOT EXISTS table_abc (
) FORMAT PLAIN ENCODE JSON;