{"record":{"id":"4048bcb81b2ab319","repo":"risingwavelabs/risingwave","slug":"column-type-mismatch-vs-column-name","errorCode":null,"errorMessage":"column type mismatch: {:?} vs {:?}, column name: {:?}","messagePattern":"column type mismatch: (.+?) vs (.+?), column name: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/handler/create_sink.rs","lineNumber":961,"sourceCode":"        sinks.push(\n            schema\n                .get_sink_by_id(*sink_id)\n                .expect(\"should exist\")\n                .clone(),\n        );\n    }\n    Ok(sinks)\n}\n\nfn derive_sink_to_table_expr(\n    sink_schema: &Schema,\n    idx: usize,\n    target_type: &DataType,\n) -> Result<ExprImpl> {\n    let input_type = &sink_schema.fields()[idx].data_type;\n\n    if !target_type.equals_datatype(input_type) {\n        bail!(\n            \"column type mismatch: {:?} vs {:?}, column name: {:?}\",\n            target_type,\n            input_type,\n            sink_schema.fields()[idx].name\n        );\n    } else {\n        Ok(ExprImpl::InputRef(Box::new(InputRef::new(\n            idx,\n            input_type.clone(),\n        ))))\n    }\n}\n\npub(crate) fn derive_default_column_project_for_sink(\n    sink: &SinkCatalog,\n    sink_schema: &Schema,\n    columns: &[ColumnCatalog],\n    user_specified_columns: bool,","sourceCodeStart":943,"sourceCodeEnd":979,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/handler/create_sink.rs#L943-L979","documentation":"`derive_sink_to_table_expr` returns a user-facing `bail!` error when the sink query's output column type does not exactly match the target table column's type. When sinking into a table, RisingWave only auto-inserts when types are identical (it builds a cast project elsewhere); here, in the default-column projection path, an exact-match check guards the expression derivation and rejects mismatches with both types and the column name.","triggerScenarios":"`CREATE SINK ... INTO <table>` where a column of the sink query has a different type than the corresponding target table column and the type cannot be matched — e.g. `INTEGER` vs `BIGINT`, `VARCHAR` vs `INTEGER`, or different `VECTOR(n)` dimensions reaching this helper from `derive_default_column_project_for_sink`.","commonSituations":"Sinking into a table created with different column types than the source; target table altered after the sink query was written; decimals/timestamps with different precision; vector columns of mismatched dimension.","solutions":["Cast columns explicitly in the sink query: `CREATE SINK s AS SELECT CAST(a AS BIGINT) AS a, ...`.","Recreate the target table with types matching the source query.","Align vector dimensions by using `VECTOR(n)` of the same n on both sides.","Check types on both sides via `information_schema.columns` before creating the sink."],"exampleFix":"// before\nCREATE SINK s AS SELECT id, qty FROM src INTO tgt; -- qty INTEGER vs tgt.qty BIGINT\n// after\nCREATE SINK s AS SELECT id, CAST(qty AS BIGINT) AS qty FROM src INTO tgt;","handlingStrategy":"validation","validationCode":"-- compare source query column types with target table before creating the sink\nSELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'src';\nSELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'tgt';","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add explicit CASTs in the sink query to match the target table types exactly.","Match vector dimensions, timestamp precision, and decimal scale on both sides.","Re-validate after ALTERs on either source or target table."],"tags":["sink","type-mismatch","sql","create-sink"],"backgroundTag":"type-mismatch","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}