#[non_exhaustive]pub enum CanonicalText {
Date,
Timestamp,
ZonedTimestamp,
Decimal {
scale: u8,
},
Float {
significant: u8,
},
Boolean,
AsCast,
}Expand description
What a value’s text is, by its type.
One classification, so no two engines can disagree about which types have a canonical text and which are written by the engine’s own cast.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Date
A calendar day: YYYY-MM-DD, as in 2026-01-05.
Timestamp
A moment with no time zone: YYYY-MM-DD HH:MM:SS, then a point and the
fraction of a second to the microsecond with its trailing zeros
dropped. A whole second has no point and no fraction:
2026-01-05 12:34:56.12 and 2026-01-05 00:00:00.
ZonedTimestamp
A moment with a time zone: the same moment in UTC, written as a
Timestamp is and then +00:00, whatever zone the
value or the session is in. 14:34:56.12 at +02:00 is
2026-01-05 12:34:56.12+00:00.
Decimal
A decimal: every digit of its declared scale after a point, and none
where the scale is zero. A DECIMAL(12, 2) ten is 10.00, a negative
half is -0.50, and the separator is always a point.
Float
A floating number: the value rounded to significant digits and
written the way C’s printf writes %.{significant}g.
Without an exponent where the rounded value’s power of ten is at
least -4 and below significant, and with one otherwise; trailing
zeros and a bare point dropped; an exponent as e, a sign and at least
two digits. A double ten is 10 (never 10.0), a tenth 0.1,
0.1 + 0.2 is 0.3, 1.5e-7 is 1.5e-07, and 10^20 is 1e+20. A
zero is 0, whatever its sign.
A double carries DOUBLE_DIGITS and a single-precision number
SINGLE_DIGITS: the most digits of a decimal that survive the trip
into the type and back. A value the source wrote with that many digits
or fewer reads back as written, and the binary noise past them — the
4 at the end of 0.30000000000000004 — is never shown. A
single-precision value reads the same on an engine that holds it as a
double. Not-a-number and the infinities have no canonical text.
Boolean
A truth value: true or false, on an engine that holds it as a
number too.
AsCast
Every other type, written by the engine’s own cast to text.