Skip to main content
You can create changefeeds on tables with more than one . Changefeeds will emit individual messages per column family on a table. For further detail, see the following sections:

Syntax

To target a table with multiple column families, set the when creating a changefeed:
To emit messages for a specific column family, use the FAMILY keyword:
You can also use on tables with column families by using the statement with split_column_families or the FAMILY keyword.
If a table has multiple column families, the FAMILY keyword will ensure the changefeed emits messages for each column family you define with FAMILY in the CREATE CHANGEFEED statement. If you do not specify FAMILY, then the changefeed will emit messages for all the table’s column families. To specify multiple families on the same table, it is necessary to define the table and family in both instances:

Message format

The response will follow a typical , but with the family name appended to the table name with a ., in the format table.family:
For , the filename will include the family name appended to the table name with a +, in the format table+primary. schema names will include the family name concatenated to the table name. The primary key columns will appear in the key for all column families, and will also appear in the value only for the families that they are a member of. For example, if the table office_dogs has a column family primary, containing the primary key and a STRING column, and a secondary column family containing a different STRING column, then you’ll receive two messages for an insert.
The changefeed targeting this table (started with split_column_families) will emit the following when there are inserts to the table:
The output shows the primary column family with 4 in the value ({"id":4,"name":"Toby"}) and the key ("key":[4]). The secondary family doesn’t contain the id column, so the primary key 4 is only in the key and not the value. For an update that only affects data in one column family, the changefeed will send one message for that update relating to the family.

Considerations

  • If you create a table without column families and then start a changefeed with the split_column_families option, it is not possible to add column families. A subsequent ALTER TABLE statement adding a column family to the table will cause the changefeed to fail.
  • When you do not specify column family names in the CREATE or ALTER TABLE statement, the family names will default to either of the following:
    • primary: Since primary is a key word, you’ll receive a syntax error if you run CREATE CHANGEFEED FOR table FAMILY primary. To avoid this syntax error, use double quotes: CREATE CHANGEFEED FOR table FAMILY "primary". You’ll receive output from the changefeed like: table.primary.
    • fam_<zero-indexed family id_<delimited list of columns: For a table that does not include a name for the family: FAMILY (id, name), you’ll receive output from the changefeed containing: table.fam_0_id_name. This references the table, the family ID and the two columns that this column family includes.
  • Creating a changefeed with is not supported on tables with more than one column family.
  • When you create a changefeed on a table with more than one column family, the changefeed will emit messages per column family in separate streams. As a result, for different column families will arrive at the under separate topics. For more details, refer to Message format.
For examples of starting changefeeds on tables with column families, see the following examples for Enterprise and basic changefeeds.

Create a changefeed on a table with column families

In this example, you’ll set up changefeeds on two tables that have . You’ll use a single-node cluster sending changes to a webhook sink for this example, but you can use any to work with tables that include column families.
  1. If you do not already have one, .
  2. Use the command to start a single-node cluster:
  3. As the root user, open the :
  4. Set your organization and license key:
  5. Enable the kv.rangefeed.enabled :
  6. In a separate terminal window, set up your HTTP server. Clone the test repository:
  7. Next make the script executable and then run the server (passing a specific port if preferred, otherwise it will default to :3000):
  8. Back in your SQL shell, create a database called cdc_demo:
  9. Set the database as the default:
  10. Create a table with two column families:
  11. Insert some data into the table:
  12. Create a second table that also defines column families:
  13. Insert some data into office_plants:
  14. Create a changefeed on the office_dogs table targeting one of the column families. Use the FAMILY keyword in the CREATE statement:
    You’ll receive one message for each of the inserts that affects the specified column family:
The ordering of messages is not guaranteed. That is, you may not always receive messages for the same row, or even the same change to the same row, next to each other.
Alternatively, create a changefeed using the FAMILY keyword across two tables:
You’ll receive one message for each insert that affects the specified column families:
This allows you to define particular column families for the changefeed to target, without necessarily specifying every family in a table.
To create a changefeed specifying two families on one table, ensure that you define the table and family in both instances:CREATE CHANGEFEED FOR TABLE office_dogs FAMILY employee, TABLE office_dogs FAMILY dogs INTO {sink};
  1. To create a changefeed that emits messages for all column families in a table, use the option:
    You’ll receive output for both of the column families in the office_dogs table:
You can find details of your changefeed job using . Changefeeds streaming to or will populate the topics field in the SHOW CHANGEFEED JOBS output.When using the FAMILY keyword, the topics field will display in the format topic.family, e.g., office_dogs.employee,office_dogs.dogs. With the split_column_families option set, topics will show the topic name and a family placeholder topic.{family}, e.g., office_dogs.{family}.
  1. Update one of the values in the table:
    This only affects one column family, which means you’ll receive one message:

See also