Expand description
The values of NUMERIC, the decimal number of PostgreSQL with no fixed width and no fixed scale, as the bytes that a vector holds.
The number is the one NumericVar holds in src/backend/utils/adt/numeric.c: a sign, a weight, base-10000 digits and a display scale. crate::Numeric does the arithmetic, the input and the output on that form, and this module only packs it.
The first byte is the class of the value, in the order of the values: negative infinity, a negative number, zero, a positive number, positive infinity and NaN, as PostgreSQL sorts them. A number then has its weight and its digits, with no zero digit at either end. A negative number has them flipped and a last word of 0xffff, so that a longer negative number sorts first. The last two bytes are the display scale. Thus the bytes before the last two order as the numbers do, and 1.0 and 1.00 have the same key and different bytes.
Lifted from crates/rudb-common/src/numeric.rs of tamnd/rudb at f5f7065a (spec/04 section 4.9).
Structs§
- Unpacked
- A value taken apart. A special value has no digits, a weight of 0 and a display scale of 0.
Constants§
- INFINITY
- NAN
- NEGATIVE
- NEGATIVE_
INFINITY - POSITIVE
NUMERIC_POS,NUMERIC_NEG,NUMERIC_NAN,NUMERIC_PINFandNUMERIC_NINF, the sign codes of PostgreSQL.
Functions§
- decode
- The value of bytes that
encodewrote. Bytes that it cannot have written read asNaN. - encode
- The bytes of a value. Zero digits at either end are dropped, and a number with no digits left is zero.
- key
- The bytes that order and compare as the number does, which leave out the display scale.
- to_text
- The text of a value, as
numeric_outwrites it: the digits with exactly the display scale.