The EXPERIMENTAL CHANGEFEED FOR statement creates a new core changefeed, which provides row-level change subscriptions.

Core changefeeds work differently than other CockroachDB SQL statements. Instead of returning a finite result set to the client, a core changefeed streams changes to the watched rows indefinitely until the underlying connection is closed or the changefeed query is canceled. This has important implications for the connection and client parameters related to server- and client-side result buffering.

For more information, see Change Data Capture.

Note:

EXPERIMENTAL CHANGEFEED FOR is the core implementation of changefeeds. For the enterprise-only version, see CREATE CHANGEFEED.

Warning:

This is an experimental feature. The interface and output are subject to change.

Required privileges

Changefeeds can only be created by superusers, i.e., members of the admin role. The admin role exists by default with root as the member.

Synopsis

> EXPERIMENTAL CHANGEFEED FOR table_name [ WITH (option [= value] [, ...]) ];

Parameters

Parameter Description
table_name The name of the table (or tables in a comma separated list) to create a changefeed for.
option / value For a list of available options and their values, see Options below.

Options

Option Value Description
updated N/A Include updated timestamps with each row.
resolved INTERVAL Periodically emit resolved timestamps to the changefeed. Optionally, set a minimum duration between emitting resolved timestamps. If unspecified, all resolved timestamps are emitted.

Example: resolved='10s'
envelope key_only / row Use key_only to emit only the key and no value, which is faster if you only want to know when the key changes.

Default: envelope=row
cursor Timestamp Emits any changes after the given timestamp, but does not output the current state of the table first. If cursor is not specified, the changefeed starts by doing a consistent scan of all the watched rows and emits the current value, then moves to emitting any changes that happen after the scan.

cursor can be used to start a new changefeed where a previous changefeed ended.

Example: CURSOR=1536242855577149065.0000000000
format json / experimental_avro Format of the emitted record. Currently, support for Avro is limited and experimental.

Default: format=json.
confluent_schema_registry Schema Registry address The Schema Registry address is required to use experimental_avro.

Avro limitations

Currently, support for Avro is limited and experimental. Below is a list of unsupported SQL types and values for Avro changefeeds:

Examples

Create a changefeed

copy
icon/buttons/copy
> EXPERIMENTAL CHANGEFEED FOR foo WITH updated, resolved;

Note that it may take a couple of seconds for records to display in the changefeed after a change is made.

table,key,value
foo,[0],"{""after"": {""a"": 0}, ""updated"": ""1549591174801796000.0000000000""}"
NULL,NULL,"{""resolved"":""1549591174801796000.0000000000""}"
foo,[1],"{""after"": {""a"": 1}, ""updated"": ""1549591188018217000.0000000000""}"

To stop streaming the changefeed, enter CTRL+C into the terminal where the changefeed is running.

For more information on how to create a core changefeed, see Change Data Capture.

Create a changefeed with Avro

copy
icon/buttons/copy
> EXPERIMENTAL CHANGEFEED FOR foo WITH format = experimental_avro, confluent_schema_registry = <schema_registry_address>;

Note that it may take a couple of seconds for records to display in the changefeed after a change is made.

To stop streaming the changefeed, enter CTRL+C into the terminal where the changefeed is running.

For more information on how to create a core changefeed, see Change Data Capture.

See also



Yes No