risingwavelabs/risingwave · error · SinkError::SqlServer

column unspecified in primary_key mismatches with the…

Error message

column {} unspecified in primary_key mismatches with the downstream SQL Server table {} PK

What it means

The mirror case of error 887: a column that is part of the downstream SQL Server table's PRIMARY KEY must also be declared in the RisingWave sink's primary_key. validate() raises this when a SQL Server PK column is not marked as RW PK (non-append-only sink).

Solutions

  1. Extend the sink's PRIMARY KEY clause to include all downstream PK columns
  2. Alter the SQL Server table's PK to match the sink's primary_key columns
  3. Switch to append_only sink type if upsert matching on the full PK is not required

Example fix

// before
CREATE SINK ... PRIMARY KEY (id) ...; -- table PK is (id, tenant_id)
// after
CREATE SINK ... PRIMARY KEY (id, tenant_id) ...;
Defensive patterns

Strategy: validation

Validate before calling

-- ensure every downstream PK column appears in the sink's PRIMARY KEY clause
SELECT c.name FROM sys.key_constraints kc
JOIN sys.index_columns ic ON ic.object_id = kc.parent_object_id AND ic.index_id = kc.unique_index_id
JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
WHERE kc.type_desc = 'PRIMARY_KEY' AND kc.parent_object_id = OBJECT_ID('target');
-- all returned names must be in the sink primary_key list

Try / catch

match sink.validate().await {
    Err(e) if e.to_string().contains("unspecified in primary_key mismatches") => extend_sink_pk_and_recreate(),
    other => other,
}

Prevention

When it happens

Trigger: Non-append-only SQL Server sink whose declared primary_key omits one or more columns that are part of the downstream table's PRIMARY KEY.

Common situations: Downstream table has a composite PK (id, tenant_id) but the sink only declares PRIMARY KEY (id); defaulting to the MV's PK which differs from the table PK.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/c542e51ac0660292. Report an issue: GitHub.

Appendix: source

Thrown at src/connector/src/sink/sqlserver.rs:238

                }
                Some(sql_server_col) => {
                    validate_data_type_compatibility(
                        &col.name,
                        &col.data_type,
                        &sql_server_col.data_type,
                    )?;
                    if self.is_append_only {
                        continue;
                    }
                    if rw_is_pk && !sql_server_col.is_pk {
                        return Err(SinkError::SqlServer(anyhow!(format!(
                            "column {} specified in primary_key mismatches with the downstream SQL Server table {} PK",
                            col.name,
                            self.config.full_object_path(),
                        ))));
                    }
                    if !rw_is_pk && sql_server_col.is_pk {
                        return Err(SinkError::SqlServer(anyhow!(format!(
                            "column {} unspecified in primary_key mismatches with the downstream SQL Server table {} PK",
                            col.name,
                            self.config.full_object_path(),
                        ))));
                    }
                }
            }
        }

        if !self.is_append_only && sql_server_pk_count != self.pk_indices.len() {
            let sql_server_pk_columns = sql_server_table_metadata
                .values()
                .filter(|metadata| metadata.is_pk)
                .map(|metadata| metadata.name.as_str())
                .collect::<Vec<_>>()
                .join(",");
            let rw_pk_columns = self
                .pk_indices

View on GitHub (pinned to 6469eb736d)