{"record":{"id":"61894a44f2e330af","repo":"risingwavelabs/risingwave","slug":"encode-bytes-requires-the-column-to-be-of-type-byt","errorCode":null,"errorMessage":"ENCODE BYTES requires the column to be of type BYTEA, but got type {}","messagePattern":"ENCODE BYTES requires the column to be of type BYTEA, but got type (.+?)","errorType":"validation","errorClass":"SinkError","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/formatter/mod.rs","lineNumber":247,"sourceCode":"                        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}\n\nimpl EncoderBuild for TextEncoder {\n    async fn build(params: EncoderParams<'_>, pk_indices: Option<Vec<usize>>) -> Result<Self> {\n        let (pk_index, schema_ref) = ensure_only_one_pk(\"TEXT\", &params, &pk_indices)?;\n        match &schema_ref.data_type() {\n            DataType::Varchar\n            | DataType::Boolean\n            | DataType::Int16\n            | DataType::Int32\n            | DataType::Int64","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/formatter/mod.rs#L229-L265","documentation":"The value encoder for BYTES found exactly one column (the count check passed) but that column is not BYTEA. Only bytea columns can be passed through as raw encoded bytes, so any other type is rejected.","triggerScenarios":"VALUE ENCODE BYTES with a single-column schema whose type is not DataType::Bytea — e.g. SELECT id FROM t WITH (value_encode='bytes').","commonSituations":"Assuming the encoder will serialize an INT/VARCHAR/JSON column into bytes automatically; writing sink SQL that selects one non-bytea column.","solutions":["Cast the column to bytea in the sink query","Ensure the payload column is declared BYTEA","Switch to value_encode='json' if you want automatic serialization"],"exampleFix":"// before\nCREATE SINK s AS SELECT id FROM t WITH (value_encode = 'bytes');\n// after\nCREATE SINK s AS SELECT id::bytea AS id FROM t WITH (value_encode = 'bytes');","handlingStrategy":"validation","validationCode":"if value_encode == \"bytes\" && schema.fields[0].data_type != DataType::Bytea {\n    return Err(\"value encode bytes requires a bytea column\");\n}","typeGuard":"fn is_bytea(f: &Field) -> bool { f.data_type == DataType::Bytea }","tryCatchPattern":null,"preventionTips":["Cast the payload column to bytea in the sink SELECT","Verify column type with DESC before configuring value encode"],"tags":["sink","type-mismatch","bytea"],"backgroundTag":"type-mismatch","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}