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§
- Numeric
Error - A
numeric(20,0)value that is not au64.
Functions§
- from_
numeric_ text - Parse a
numeric(20,0)::textresult back into a counter. - to_
numeric_ text - Render a counter for a
$n::numericparameter.