{"record":{"id":"cd9fa9a80aa9b258","repo":"risingwavelabs/risingwave","slug":"numeric-out-of-range-underflow","errorCode":null,"errorMessage":"Numeric out of range: underflow","messagePattern":"Numeric out of range: underflow","errorType":"exception","errorClass":"ExprError","httpStatus":null,"severity":"error","filePath":"src/expr/core/src/error.rs","lineNumber":61,"sourceCode":"    /// 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\n    #[error(\"Invalid parameter {name}: {reason}\")]\n    // TODO(error-handling): should prefer use error types than strings.\n    InvalidParam {\n        name: &'static str,\n        reason: Box<str>,\n    },","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/expr/core/src/error.rs#L43-L79","documentation":"ExprError::NumericUnderflow is raised when a numeric operation or cast produces a value below the minimum representable value of the target type — i.e. an underflow, reported distinctly from overflow.","triggerScenarios":"Evaluating arithmetic (e.g. multiplying two very small-magnitude numerics/negatives) or narrowing casts where the result is below the target type's lower bound.","commonSituations":"Casting large negative numerics to narrow signed types; repeated division/multiplication driving values to extremes; financial data with tiny decimal scales.","solutions":["Use a wider target type for the operation or cast","Clamp inputs to a safe range before computing","Use try_cast to convert failures into NULL","Investigate the offending input rows from query context"],"exampleFix":"// before\nSELECT col::real FROM t; -- value below real min\n// after\nSELECT try_cast(col as real) FROM t;","handlingStrategy":"validation","validationCode":"// pre-check lower bound before narrowing\nif v < min_allowed { /* clamp or NULL before cast */ }","typeGuard":null,"tryCatchPattern":"match eval_result {\n    Err(e) if e.to_string().contains(\"underflow\") => {\n        // widen type or clamp to min representable value\n    }\n    r => r,\n}","preventionTips":["Use try_cast for potentially underflowing casts","Clamp at ingestion","Prefer wider types for negative-extreme data"],"tags":["numeric","underflow","rust","arithmetic"],"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"}