Column selection for PostgreSQL
Use column selection to ingest only the table columns you need. This page covers the requirements that are specific to PostgreSQL.
Select columns to ingest
By default, the pipeline ingests all columns in the tables you select. To ingest only some columns, set include_columns or exclude_columns in the table configuration. For a description of each property and example pipeline definitions, see Select columns to ingest.
How the pipeline handles your column selection depends on the pipeline type:
- Ingestion gateway and ingestion pipeline: The pipeline ingests the columns you include, or all columns except the ones you exclude. It doesn't check whether your selection keeps the table's key columns, so keep the columns described in Required key columns selected.
- Integrated change data capture (CDC) pipeline: The pipeline also checks that your selection keeps the table's key columns. If it doesn't, the table fails to ingest. See Required key columns.
Required key columns
CDC keeps your destination table in sync by matching each change to a row using the source table's key. The connector picks the key in this order, and your column selection must keep all of that key's columns:
-
Primary key: If the table has a primary key, keep all primary key columns. Unique key columns are optional.
-
Unique key: If the table has no primary key, keep all columns of the first unique key whose columns are all
NOT NULL. Unique constraints come before unique indexes created withCREATE UNIQUE INDEX, and within each group, unique keys are ordered alphabetically by name. For example, if unique constraintsuk_emailanduk_phoneboth have onlyNOT NULLcolumns, the connector usesuk_email.To see a table's unique keys, run
\d <table>inpsql. In theIndexessection of the output, unique constraints are markedUNIQUE CONSTRAINTand unique indexes are markedUNIQUE. To list the unique keys in the order the connector considers them, run the following query. The connector uses the first row whereall_not_nullistrue.SQLSELECT c.relname AS key_name,CASE WHEN con.oid IS NOT NULL THEN 'constraint' ELSE 'index' END AS kind,(SELECT string_agg(a.attname, ', ' ORDER BY k.ord)FROM unnest(i.indkey) WITH ORDINALITY AS k(attnum, ord)JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = k.attnum) AS columns,(SELECT bool_and(a.attnotnull)FROM pg_attribute aWHERE a.attrelid = i.indrelid AND a.attnum = ANY (i.indkey)) AS all_not_nullFROM pg_index iJOIN pg_class c ON c.oid = i.indexrelidLEFT JOIN pg_constraint con ON con.conindid = i.indexrelid AND con.contype = 'u'WHERE i.indrelid = '<schema>.<table>'::regclassAND i.indisunique AND NOT i.indisprimaryAND i.indexprs IS NULL AND i.indpred IS NULL AND i.indisvalidORDER BY con.oid IS NULL, c.relname;Replace
<schema>and<table>with the table's schema and name. If a name has uppercase letters or special characters, wrap it in double quotes inside the string, for example'"MySchema"."MyTable"'::regclass. -
No usable key: If the table has neither a primary key nor a qualifying unique key, you can include or exclude any columns. These unique keys don't qualify: a unique key with a nullable column, a partial unique index, a unique index on an expression, and an invalid unique index, which
\dmarksINVALID.
To keep a column, list it in include_columns, or leave it out of exclude_columns.
In an integrated CDC pipeline, if your column selection drops a required key column, the table fails to ingest with the error INGESTION_GATEWAY_KEY_COLUMN_NOT_SELECTED. To recover, update include_columns or exclude_columns so that the key is fully selected, and then run a full refresh of the table. See Fully refresh target tables.
Change column selection for a table that is already ingesting
In an integrated CDC pipeline, you can edit include_columns or exclude_columns for a table at any time, and the change is saved to your pipeline. However, changing the column selection for a table that is already being ingested requires a full refresh of that table. If you change the selection and don't run a full refresh of the affected table in the same update, the pipeline update fails with the error CANNOT_CHANGE_COLUMN_SELECTION_WITHOUT_FULL_REFRESH.