{"record":{"id":"0b0d084c87cae373","repo":"risingwavelabs/risingwave","slug":"conversion-of-sql-server-money-to-data-type-is-n","errorCode":null,"errorMessage":"conversion of SQL Server money to {data_type} is not supported","messagePattern":"conversion of SQL Server money to (.+?) is not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/connector/src/parser/sql_server.rs","lineNumber":136,"sourceCode":"fn coerce_scalar_to_target_type(scalar: ScalarImpl, target_type: &DataType) -> ScalarImpl {\n    match (scalar, target_type) {\n        // SQL Server validator allows integer upcast (e.g. `int` -> `BIGINT`).\n        // Coerce snapshot values to the target RW type to keep validation and execution consistent.\n        (ScalarImpl::Int16(v), DataType::Int32) => ScalarImpl::Int32(v as i32),\n        (ScalarImpl::Int16(v), DataType::Int64) => ScalarImpl::Int64(v as i64),\n        (ScalarImpl::Int32(v), DataType::Int64) => ScalarImpl::Int64(v as i64),\n        // SQL Server `real` may map to `FLOAT` in RW validator.\n        (ScalarImpl::Float32(v), DataType::Float64) => ScalarImpl::Float64((v.0 as f64).into()),\n        (scalar, _) => scalar,\n    }\n}\n\nfn try_convert_money_i64_to_type(value: i64, data_type: &DataType) -> anyhow::Result<ScalarImpl> {\n    match data_type {\n        DataType::Decimal => Ok(ScalarImpl::Decimal(\n            Decimal::from(value) / Decimal::from_str(\"10000\").unwrap(),\n        )),\n        _ => bail!(\"conversion of SQL Server money to {data_type} is not supported\"),\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use risingwave_common::types::F32;\n\n    use super::*;\n\n    #[test]\n    fn test_integer_upcast_coercion() {\n        let v = coerce_scalar_to_target_type(ScalarImpl::Int32(7), &DataType::Int64);\n        assert_eq!(v, ScalarImpl::Int64(7));\n\n        let v = coerce_scalar_to_target_type(ScalarImpl::Int16(7), &DataType::Int32);\n        assert_eq!(v, ScalarImpl::Int32(7));\n\n        let v = coerce_scalar_to_target_type(ScalarImpl::Int16(7), &DataType::Int64);","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/parser/sql_server.rs#L118-L154","documentation":"SQL Server's `money` type is delivered as an i64 scaled by 10000. The connector only converts it to a RisingWave Decimal; any other target DataType is rejected rather than silently losing precision. The money-to-other-types mapping is intentionally unsupported.","triggerScenarios":"`sql_server_cell_to_rw_datum` detects a money column and calls `try_convert_money_i64_to_type(value, data_type)`; the function bails whenever `data_type` is not `DataType::Decimal` (e.g. the RW column is Float64 or Varchar).","commonSituations":"RW table created against a SQL Server source with a money column declared as float/double; schema inference or hand-written schema chose a non-decimal type; expectation of automatic numeric coercion for money.","solutions":["Declare the RW column for the money source column as DECIMAL so the conversion succeeds.","Recreate/alter the RW table changing the column type to decimal.","Cast the money column on the SQL Server side (e.g. `CAST(col AS float)`) and declare the matching RW type.","Avoid mapping money to float/double; precision loss is why it is unsupported."],"exampleFix":"-- before\nCREATE TABLE t (amount double) FROM sql_server ...; -- money source column\n-- after\nCREATE TABLE t (amount decimal) FROM sql_server ...;","handlingStrategy":"validation","validationCode":"// Ensure any SQL Server money column maps to RW decimal before table creation:\nfn money_target_ok(dt: &DataType) -> bool { matches!(dt, DataType::Decimal) }\n-- Detect money columns in SQL Server via sys.columns.","typeGuard":"fn money_target_ok(dt: &DataType) -> bool { matches!(dt, DataType::Decimal) }","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"money\") && e.to_string().contains(\"not supported\") => {\n        // change the RW column type to decimal and recreate the table\n    }\n    other => other?,\n}","preventionTips":["Always map SQL Server money columns to RW decimal.","Search sys.columns for money/smallmoney and review their RW mappings.","Avoid float/double for money to preserve precision.","Cast money to another SQL Server type explicitly if decimal is not desired."],"tags":["sql-server","type-conversion","money","cdc"],"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"}