Skip to main content

Module numeric

Module numeric 

Source
Expand description

Checked conversion between wire u64 counters and PostgreSQL numeric(20,0).

The contract’s 64-bit counters — seq, fence_token, byte_size — span the full u64 range, and PostgreSQL has no unsigned 64-bit type: bigint tops out at 2^63-1, exactly half of it. numeric(20,0) holds the range, so the schema uses it.

Getting the value across is where precision goes to die. A driver that maps numeric through f64 silently rounds above 2^53, and one that maps it through i64 overflows above 2^63. This module refuses to go through either: values cross as DECIMAL TEXT, which is exact for every u64 by construction, and parse back under a bounds check. That is also why the queries in this crate say seq::text and $1::numeric rather than binding a numeric type — the cast is the conversion.

Structs§

NumericError
A numeric(20,0) value that is not a u64.

Functions§

from_numeric_text
Parse a numeric(20,0)::text result back into a counter.
to_numeric_text
Render a counter for a $n::numeric parameter.