EXPERIMENTAL CHANGEFEED FOR

New in v19.1: 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

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

Parameters

ParameterDescription
table_nameThe name of the table (or tables in a comma separated list) to create a changefeed for.
option / valueFor a list of available options and their values, see Options below.



### Options


OptionValueDescription
updatedN/AInclude updated timestamps with each row.
resolvedINTERVALPeriodically 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'
envelopekey_only / rowUse 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
cursorTimestampEmits 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
formatjson / experimental_avroFormat of the emitted record. Currently, support for Avro is limited and experimental. Default: format=json.
confluent_schema_registrySchema Registry addressThe 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:

  • Decimals must have precision specified.
  • Decimals with NaN or infinite values cannot be written in Avro.

Note:

To avoid NaN or infinite values, add a CHECK constraint to prevent these values from being inserted into decimal columns.

Examples

Create a changefeed

  1. > 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.

  1. table,key,value
  2. foo,[0],"{""after"": {""a"": 0}, ""updated"": ""1549591174801796000.0000000000""}"
  3. NULL,NULL,"{""resolved"":""1549591174801796000.0000000000""}"
  4. 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

  1. > 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

Was this page helpful?
YesNo