risingwavelabs/risingwave · error

relative_error={} does not satisfy 0.0 < relative_error < 1.

Error message

relative_error={} does not satisfy 0.0 < relative_error < 1.0

What it means

Thrown when binding an ordered-set aggregate (e.g. `approx_percentile` with a relative_error argument). The binder parses the second argument as a literal float and validates that it lies strictly between 0.0 and 1.0; values <= 0.0 or >= 1.0 are rejected with this error.

Source

Thrown at src/frontend/src/binder/expr/function/aggregate.rs:166

                            kind
                        ))
                    })?;
                }
            }
            (AggType::Builtin(PbAggKind::Mode), 0, [_arg]) => {}
            (AggType::Builtin(PbAggKind::ApproxPercentile), 1..=2, [_percentile_col]) => {
                let percentile = &mut direct_args[0];
                decimal_to_float64(percentile, kind)?;
                match direct_args.len() {
                    2 => {
                        let relative_error = &mut direct_args[1];
                        decimal_to_float64(relative_error, kind)?;
                        if let Some(relative_error) = relative_error.as_literal()
                            && let Some(relative_error) = relative_error.get_data()
                        {
                            let relative_error = relative_error.as_float64().0;
                            if relative_error <= 0.0 || relative_error >= 1.0 {
                                bail!(
                                    "relative_error={} does not satisfy 0.0 < relative_error < 1.0",
                                    relative_error,
                                )
                            }
                        }
                    }
                    1 => {
                        let relative_error: ExprImpl = Literal::new(
                            ScalarImpl::Float64(0.01.into()).into(),
                            DataType::Float64,
                        )
                        .into();
                        direct_args.push(relative_error);
                    }
                    _ => {
                        return Err(ErrorCode::InvalidInputSyntax(
                            "invalid direct args for approx_percentile aggregation".to_owned(),
                        )

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Pass a relative_error literal strictly between 0 and 1, e.g. `approx_percentile(col, 0.01)`.
  2. Convert percentage values by dividing by 100 (5% -> 0.05).
  3. Check the function signature documentation for the exact ordered-set aggregate argument order.

Example fix

// before
SELECT approx_percentile(value, 1.0) FROM t;
// after
SELECT approx_percentile(value, 0.01) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

if !(relative_error > 0.0 && relative_error < 1.0) {
  throw new Error("relative_error must be strictly between 0 and 1");
}

Type guard

function isValidRelativeError(v: number): boolean { return Number.isFinite(v) && v > 0 && v < 1; }

Try / catch

try {
  await client.query("SELECT approx_percentile(v, $1) FROM t", [rel]);
} catch (e) {
  if (String(e.message).includes("does not satisfy 0.0 < relative_error < 1.0")) {
    // clamp/correct the argument and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Executing an ordered-set aggregate like `approx_percentile(x, 1.0)`, `approx_percentile(x, 0.0)`, or any negative/out-of-range literal as the relative_error argument; also non-literal arguments are skipped by this check (only literals are validated here).

Common situations: Users writing percentile accuracy as a percentage (e.g. 5 meaning 5%) instead of a fraction (0.05); copy-pasted SQL from other engines with different argument semantics; typos like `1` instead of `0.1`.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/f2009e18a71f59b8. Report an issue: GitHub.