Syntax
Parameters
| Parameter | Description |
|---|---|
<table_name> | An identifier for the table. Must be unique within the schema. |
<column_name> <data_type> | Columns to maintain, matching the stream’s columns. Omit the whole list to infer columns and merge key from the stream; the inferred form also adds a JSON overflow column for undeclared source fields. |
PRIMARY KEY ... NOT ENFORCED | The merge key: the column set identifying a row across its lifetime, normally the source primary key. Composite keys are supported. Required in the explicit form; the NOT ENFORCED keyword is mandatory. The key is trusted, not validated. |
PRIMARY INDEX | Optional sort order for the table, independent of the merge key. Defaults to the merge key columns. |
FROM STREAM <stream_name> | The stream that feeds the table. One stream feeds one CDC table. |
WITH options
| Option | Values | Default | Description |
|---|---|---|---|
merge_mode | 'read', 'write' | 'read' | Where superseded row versions are excluded: on the read side through deletion masks, or eagerly on the write path. See merge modes. |
cascade_interval | INTERVAL '<n>' SECOND|MINUTE|HOUR, 1 second to 24 hours | 60 seconds | read mode: how often the background cascade consolidates staged changes into the base table. Does not affect result freshness; reads are always current. |
Notes
CREATE CDC TABLErecords metadata only; ingestion starts withALTER CDC TABLE ... RESUME.- Merge-key columns are implicitly
NOT NULL. - In
readmode, merge-key columns must beBOOLEAN,INTEGER,BIGINT,DATE,TIMESTAMP,TIMESTAMPTZ,NUMERIC, orTEXT(NUMERIConly as a single-column key). Usemerge_mode = 'write'for other key types. - For a stream over a partitioned Postgres source, every source partition-key column must be part of the merge key.
- Column names beginning with
__, andlast_seq, are reserved for CDC bookkeeping. merge_modecannot be changed after creation.- In
readmode, direct DML,TRUNCATE, column-levelALTER TABLE,SET PRIMARY INDEX, and aggregating indexes are rejected; renaming the table is allowed.writetables behave like ordinary tables.
Examples
Mirror a Postgres table
Mirror a MongoDB collection with an inferred schema
Sort the table for analytics instead of by key
ALTER CDC TABLE
Controls the ingest worker of a CDC table:RESUMEbinds the ingest worker to the engine that runs the statement and persists the enabled state, so ingestion resumes automatically after an engine restart. The firstRESUMEbackfills the table from a source snapshot before streaming.SUSPENDstops the worker without a final consolidation. For Postgres sources, the idle replication slot retains WAL on the source while suspended.CASCADEapplies toreadmode and triggers the consolidation that otherwise runs everycascade_interval.
DROP TABLE
DROP TABLE <table_name> drops a CDC table together with its hidden staging storage and stops its ingest worker. Dropping the table does not drop the stream; see DROP STREAM for source-side cleanup.
Related
- CDC tables: semantics, merge modes, monitoring.
- CREATE STREAM: define the change feed.
information_schema.cdc_ingests: ingest state, progress, and errors.