{"record":{"id":"2ebd38080fce0a14","repo":"risingwavelabs/risingwave","slug":"casting-to-0-out-of-range","errorCode":null,"errorMessage":"Casting to {0} out of range","messagePattern":"Casting to (.+?) out of range","errorType":"exception","errorClass":"ExprError","httpStatus":null,"severity":"error","filePath":"src/expr/core/src/error.rs","lineNumber":55,"sourceCode":"    }\n}\n\n/// The error type for expression operations.\n#[derive(Error, ReportDebug)]\npub enum ExprError {\n    /// A collection of multiple errors in batch evaluation.\n    #[error(\"multiple errors:\\n{1}\")]\n    Multiple(ArrayRef, MultiExprError),\n\n    // Ideally \"Unsupported\" errors are caught by frontend. But when the match arms between\n    // frontend and backend are inconsistent, we do not panic with `unreachable!`.\n    #[error(\"Unsupported function: {0}\")]\n    UnsupportedFunction(String),\n\n    #[error(\"Unsupported cast: {0} to {1}\")]\n    UnsupportedCast(DataType, DataType),\n\n    #[error(\"Casting to {0} out of range\")]\n    CastOutOfRange(&'static str),\n\n    #[error(\"Numeric out of range\")]\n    NumericOutOfRange,\n\n    #[error(\"Numeric out of range: underflow\")]\n    NumericUnderflow,\n\n    #[error(\"Numeric out of range: overflow\")]\n    NumericOverflow,\n\n    #[error(\"Division by zero\")]\n    DivisionByZero,\n\n    #[error(\"Parse error: {0}\")]\n    // TODO(error-handling): should prefer use error types than strings.\n    Parse(Box<str>),\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/expr/core/src/error.rs#L37-L73","documentation":"ExprError::CastOutOfRange signals that a value could not be cast into the target type because it exceeds the target's representable range (e.g. a large int64 cast to int16). It differs from NumericOutOfRange in that the failing type name is included in the message.","triggerScenarios":"Executing a cast expression (e.g. `::smallint`, decimal to float narrowing) where the source value exceeds the destination type's min/max during batch evaluation.","commonSituations":"Dirty data in a column; ETL migrations casting wide types to narrow ones; user SQL with explicit narrow casts over real data.","solutions":["Use a wider target type for the cast","Use try_cast to get NULL instead of an error","Clamp or validate source values before casting","Clean out-of-range rows from the source data"],"exampleFix":"// before\nSELECT col::smallint FROM t;\n// after\nSELECT try_cast(col as smallint) FROM t;","handlingStrategy":"validation","validationCode":"// pre-check range before casting (pseudo)\nif v < i16::MIN as i64 || v > i16::MAX as i64 {\n    // handle before casting to smallint\n}","typeGuard":null,"tryCatchPattern":"match eval_result {\n    Err(e) if e.to_string().contains(\"out of range\") => {\n        // NULL-out or widen the target type\n    }\n    r => r,\n}","preventionTips":["Use try_cast when data may exceed target ranges","Profile min/max of columns before narrowing casts","Clamp values at ingestion time"],"tags":["cast","out-of-range","rust","expression"],"backgroundTag":"value-out-of-range","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"}