pub struct NumericKey { /* private fields */ }Expand description
r1039 — an exact-decimal index key, canonical so that representation equality IS value equality.
That property is the whole reason this is a struct rather than the
(scaled, scale) pair the value carries. 1.5 and 1.50 are the
same NUMERIC (PG18.4: 1.5::numeric = 1.50::numeric is true) and
arrive here as (15, 1) and (150, 2). A B-tree keyed on the raw
pair would file them apart, so WHERE n = 1.5 would miss a row stored
as 1.50 — an index changing the answer, which is the one thing an
index may never do. BigNumeric::cmp carries the same warning and
declines to implement Ord for exactly this reason; a KEY cannot
decline, so it normalizes instead.
Canonical form: significant decimal digits with no leading and no
trailing zeros, most significant first, plus the decimal exponent of
the leading digit. Zero is the empty digit vector with neg == false
and exp == 0, so there is no -0.
Ordering is PG’s, measured: -Infinity < -1 < 0 < 1 < Infinity < NaN,
and NaN = NaN.
Implementations§
Source§impl NumericKey
impl NumericKey
Sourcepub fn from_numeric(scaled: i128, scale: u16, kind: NumericKind) -> Self
pub fn from_numeric(scaled: i128, scale: u16, kind: NumericKind) -> Self
The key for a Value::Numeric’s three fields.
Public because the ORDER BY key wants the same canonical form the index key uses: two sort keys that disagree about which of two NUMERICs is larger is the same class of defect as an index that disagrees with a scan, and one definition is how they stay honest.
Sourcepub fn from_big(b: &BigNumeric) -> Self
pub fn from_big(b: &BigNumeric) -> Self
The key for a mantissa that overflowed i128. The two
representations of one value land on one key.
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
The f64 this key means, for the one comparison PG defines that
way: numeric against float8 demotes the numeric.
Lossy by construction — that is the point, and it is why nothing else uses it.
Trait Implementations§
Source§impl Clone for NumericKey
impl Clone for NumericKey
Source§fn clone(&self) -> NumericKey
fn clone(&self) -> NumericKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more