Skip to main content
Nightly Feature
This feature is currently in private preview. Contact support@firebolt.io to request early access.
Creates a managed table that Firebolt maintains continuously from a change stream: one live row per merge key, with source inserts, updates, and deletes applied in order. See CDC tables for semantics, merge modes, and performance characteristics.

Syntax

Parameters

WITH options

Notes

  • CREATE CDC TABLE records metadata only. ALTER CDC TABLE ... ATTACH STREAM names the stream that feeds the table, and ingestion starts with ALTER CDC TABLE ... RESUME. One stream feeds one CDC table.
  • CDC tables are created and ingested on single-node Engines, and any Engine can query them. CREATE CDC TABLE and ALTER CDC TABLE ... RESUME return an error on an Engine with more than one node. SUSPEND, ATTACH STREAM, and DETACH STREAM are still accepted, so a CDC table on an Engine that was resized can be stopped and detached.
  • Merge-key columns are implicitly NOT NULL.
  • In read mode, merge-key columns must be BOOLEAN, INTEGER, BIGINT, DATE, TIMESTAMP, TIMESTAMPTZ, NUMERIC, or TEXT (NUMERIC only as a single-column key). Use merge_mode = 'write' for other key types.
  • Column names beginning with $ or __ are reserved for CDC bookkeeping.
  • merge_mode cannot be changed after creation.
  • In read mode, direct DML, TRUNCATE, column-level ALTER TABLE, and aggregating indexes are rejected; renaming the table is allowed. write tables behave like ordinary tables.
  • A PRIMARY INDEX expression is computed for every row the table writes, a delete included. A delete stores NULL in each nullable column and a placeholder in each NOT NULL column outside the merge key (0, '', FALSE, 1970-01-01, an empty array), so an expression over such a column sees that value too: CAST(code AS INT) fails on the '' of a deleted row. CREATE CDC TABLE rejects an expression that fails on that row unless it also reads a merge-key column, whose value a delete keeps. Use forms that cannot fail, such as TRY_CAST.
  • A change the expression fails on is retried until the retry budget runs out, and then the attachment stops with state = 'error' and the reason in information_schema.cdc_ingests. To recover, replace the expression, either with ALTER TABLE ... SET PRIMARY INDEX to columns or by recreating the table, then detach the stream and start a new binding.
  • ALTER TABLE ... SET PRIMARY INDEX takes column names and changes the order data is written in from then on, as on any table. ALTER TABLE ... DROP PRIMARY INDEX is rejected: a CDC table always has a primary index.

Examples

Mirror a Postgres table

Mirror a MongoDB collection

A MongoDB stream’s columns are always _id, _shard_key and doc, so the table’s are too. The table is keyed by _id and _shard_key:

Sort a MongoDB collection by a document field

A query filtering on the same expression, such as WHERE JSON_VALUE(doc.customer.city) = 'Berlin', uses the primary index to skip the tablets and granules that cannot hold 'Berlin'.

Sort the table for analytics instead of by key

ALTER CDC TABLE

Attaches a stream to a CDC table and controls its ingest worker:
  • ATTACH STREAM takes a stream whose columns match the table’s. Attaching the stream the table was detached from continues where it stopped; attaching a stream that has not loaded a table before reloads the table from that stream’s snapshot on the next RESUME. A stream that has already loaded a table does not load another one, so mirroring into a new table needs a new stream.
  • DETACH STREAM stops the worker and unlinks the stream. The table stays queryable at its last state.
  • RESUME binds the ingest worker to the Engine that runs the statement and persists the enabled state. A worker that an earlier RESUME started on another Engine stops after the statement it is running finishes (for an initial load, after the whole load) and after any cascade already in progress. After an Engine restart, run RESUME again on the Engine where ingestion should continue. The first RESUME backfills the table from a source snapshot before streaming. RESUME is rejected while the attachment is in error (see CDC tables); the error includes the recorded reason.
  • RESUME requires a single-node Engine. On an Engine with more than one node it returns an error and starts nothing.
  • SUSPEND stops the worker without a final consolidation. For Postgres sources, the idle replication slot retains WAL on the source while suspended. On an attachment in error, SUSPEND has no effect; a worker still applying what it had staged continues until it is done.

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.