Adding or removing a changefeed
Warning
Supported only for row-oriented tables. Support for column-oriented tables is currently under development.
ADD CHANGEFEED <name> WITH (<option> = <value>[, ...])
: Adds a changefeed with the specified name and options.
Changefeed options
MODE
: Operation mode. Specifies what to write to a changefeed each time table data is altered.KEYS_ONLY
: Only the primary key components and change flag are written.UPDATES
: Updated column values that result from updates are written.NEW_IMAGE
: Any column values resulting from updates are written.OLD_IMAGE
: Any column values before updates are written.NEW_AND_OLD_IMAGES
: A combination ofNEW_IMAGE
andOLD_IMAGE
modes. Any column values prior to and resulting from updates are written.
FORMAT
: Data write format.JSON
: Write data in JSON format.DEBEZIUM_JSON
: Write data in the Debezium-like JSON format.
VIRTUAL_TIMESTAMPS
: Enabling/disabling virtual timestamps. Disabled by default.RETENTION_PERIOD
: Record retention period. The value type isInterval
and the default value is 24 hours (Interval('PT24H')
).TOPIC_MIN_ACTIVE_PARTITIONS
: The number of topic partitions. By default, the number of topic partitions is equal to the number of table partitions.INITIAL_SCAN
: Enables/disables initial table scan. Disabled by default.
The code below adds a changefeed named updates_feed
, where the values of updated table columns will be exported in JSON format:
ALTER TABLE `series` ADD CHANGEFEED `updates_feed` WITH (
FORMAT = 'JSON',
MODE = 'UPDATES'
);
Records in this changefeed will be stored for 24 hours (default value). The code in the following example will create a changefeed with a record retention period of 12 hours:
ALTER TABLE `series` ADD CHANGEFEED `updates_feed` WITH (
FORMAT = 'JSON',
MODE = 'UPDATES',
RETENTION_PERIOD = Interval('PT12H')
);
The example of creating a changefeed with enabled virtual timestamps:
ALTER TABLE `series` ADD CHANGEFEED `updates_feed` WITH (
FORMAT = 'JSON',
MODE = 'UPDATES',
VIRTUAL_TIMESTAMPS = TRUE
);
Example of creating a changefeed with initial scan:
ALTER TABLE `series` ADD CHANGEFEED `updates_feed` WITH (
FORMAT = 'JSON',
MODE = 'UPDATES',
INITIAL_SCAN = TRUE
);
DROP CHANGEFEED
: Deletes the changefeed with the specified name. The code below deletes the updates_feed
changefeed:
ALTER TABLE `series` DROP CHANGEFEED `updates_feed`;