Skip to main content

Module coerce

Module coerce 

Source
Expand description

Postgres-semantic value coercion for planner use-sites.

The planner matches sqlparser::ast::Value in numeric contexts (LIMIT, OFFSET, fusion weights, …). When a parameter was sent over the pgwire Parse message with Type::UNKNOWN — the default for drivers that don’t pre-fetch OIDs, e.g. postgres-js with fetch_types: false — our bind layer emits it as Value::SingleQuotedString (we have no type information to do otherwise at bind time, and a guess-and-coerce approach would silently corrupt string parameters bound into string columns).

Postgres’ model: UNKNOWN literals stay uncoerced until the planner has context, and the planner then resolves them by the surrounding operator / column type. These helpers are the single chokepoint implementing that resolution for numeric contexts. Any future numeric use-site must route through here — a raw match Value::Number ignores UNKNOWN-coerced literals and re-introduces the silent match-failure bug class.

Functions§

as_f64_literal
Resolve a Value into an f64 if numeric-shaped.
as_usize_literal
Resolve a Value into a usize if numeric-shaped.
expr_as_usize_literal
Resolve an Expr::Value into a usize if numeric-shaped. Thin wrapper that unpacks the ExprValue layer so callers reading LIMIT/OFFSET clauses don’t each re-write the unpack.