Skip to main content
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. For more details about the differences between sources and tables, see here.

Syntax

Notes

  • 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. See also Identifiers.
  • 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> timestamptz AS proctime()) when creating the table or source. See also proctime().
  • For a table with schema from external connector, use * to represent all columns from the external connector first, so that you can define a generated column on table with an external connector. Alternatively, you can partially combine the schema with generated columns or apply the schema directly to define the table structure. See the examples below:

Parameters

Please distinguish between the parameters set in the FORMAT and ENCODE options and those set in the WITH clause. Ensure that you place them correctly and avoid any misuse.

Append only

The append-only table does not support delete or update operations, nor does it support non-append-only upstream connectors. There are two main reasons for using append-only tables:
  • Certain features are exclusively available for append-only tables, such as watermark and TTL (Time-To-Live).
  • Streaming jobs created downstream from append-only tables can leverage their append-only property to optimize performance.

Watermarks

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.

TTL of append-only table

Data in an append-only table cannot be deleted with DELETE statements. Therefore, RisingWave provides TTL (Time-To-Live) feature to automatically clean up expired data in the table. However, please note that this cleanup only applies to the data within the table itself—it does not affect downstream materialized views or other streaming jobs. If you need to clean up data in downstream materialized views used in queries, you should use a Temporal Filter in the downstream streaming job.

PK conflict behavior

The record with insert operation could introduce duplicate records with the same primary key in the table. In that case, an alternative action specified by the ON CONFLICT clause will be adopted. The record can come from Insert DML statement, external connectors of the table, or sinks into the table CREATE SINK INTO. The action could one of the following. A column not in the primary key can be specified as the version column for DO UPDATE FULL and DO UPDATE IF NOT NULL. When version column is specified, the insert operation will take effect only when the newly inserted value is greater or equal than the exist data record in the table’s specified column.
  • IGNORE: Ignore the newly inserted record.
  • OVERWRITE [WITH VERSION COLUMN(col_name)]: Replace the existing row in the table. When version column is specified, the existing row will be replaced only when the newly inserted value is greater or equal than the existing data record in the table’s specified column.
  • DO UPDATE IF NOT NULL [WITH VERSION COLUMN(col_name)]: Only replace those fields which is not NULL in the inserted row. If version column is specified but the inserted row’s version field is NULL, the version column will not take effect.
The delete and update operation on the table cannot break the primary key constraint on the table, so the option will not take effect for those cases.
When DO UPDATE IF NOT NULL behavior is applied, DEFAULT clause is not allowed on the table’s columns.

Example

The statement below creates a table that has three columns.
The statement below creates a table that includes nested tables.
The statement below creates a table with a Kafka broker as the source.