{"record":{"id":"9cda084e3dd8f71e","repo":"risingwavelabs/risingwave","slug":"encode-bytes-requires-exactly-one-column-got-c","errorCode":null,"errorMessage":"ENCODE BYTES requires exactly one column, got {} columns","messagePattern":"ENCODE BYTES requires exactly one column, got (.+?) columns","errorType":"validation","errorClass":"SinkError","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/formatter/mod.rs","lineNumber":237,"sourceCode":"        match pk_indices {\n            // This is being used as a key encoder\n            Some(_) => {\n                let (pk_index, schema_ref) = ensure_only_one_pk(\"BYTES\", &params, &pk_indices)?;\n                if let DataType::Bytea = schema_ref.data_type() {\n                    Ok(BytesEncoder::new(params.schema, pk_index))\n                } else {\n                    Err(SinkError::Config(anyhow!(\n                        \"The key encode is BYTES, but the primary key column {} has type {}\",\n                        schema_ref.name,\n                        schema_ref.data_type\n                    )))\n                }\n            }\n            // This is being used as a value encoder\n            None => {\n                // Ensure the schema has exactly one column and it's of type BYTEA\n                if params.schema.len() != 1 {\n                    return Err(SinkError::Config(anyhow!(\n                        \"ENCODE BYTES requires exactly one column, got {} columns\",\n                        params.schema.len()\n                    )));\n                }\n\n                let field = &params.schema.fields[0];\n                if let DataType::Bytea = field.data_type {\n                    Ok(BytesEncoder::new(params.schema, 0))\n                } else {\n                    Err(SinkError::Config(anyhow!(\n                        \"ENCODE BYTES requires the column to be of type BYTEA, but got type {}\",\n                        field.data_type\n                    )))\n                }\n            }\n        }\n    }\n}","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/formatter/mod.rs#L219-L255","documentation":"As a value encoder, ENCODE BYTES passes the single row value through as raw bytes, so the schema must contain exactly one column. The builder throws when the sink schema has any other number of columns.","triggerScenarios":"build() in the value-encoder branch (pk_indices = None) where params.schema.len() != 1 — e.g. sinking a multi-column table with VALUE ENCODE BYTES.","commonSituations":"Applying 'bytes' value encoding to a normal relational sink; forgetting that bytes value encoding is meant for opaque pre-serialized payloads.","solutions":["Reduce the sink output to a single BYTEA column (SELECT payload FROM ...)","Use VALUE ENCODE JSON/AVRO/PROTOBUF for multi-column rows","If a key is needed, configure key encode separately — value bytes mode never allows extra columns"],"exampleFix":"// before\nCREATE SINK s AS SELECT a, b FROM t WITH (value_encode = 'bytes');\n// after\nCREATE SINK s AS SELECT encode(a::varchar || b::varchar, 'escape')::bytea AS payload FROM t WITH (value_encode = 'bytes');","handlingStrategy":"validation","validationCode":"if value_encode == \"bytes\" && schema.len() != 1 {\n    return Err(format!(\"value encode bytes requires exactly 1 column, got {}\", schema.len()));\n}","typeGuard":"fn is_single_col(schema: &Schema) -> bool { schema.len() == 1 }","tryCatchPattern":null,"preventionTips":["Use JSON/Avro for multi-column value payloads","Reserve 'bytes' value encoding for opaque pre-serialized payloads"],"tags":["sink","schema","bytes","value-encoder"],"backgroundTag":"invalid-argument-value","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}