pub enum Literal {
Show 14 variants
Integer(i64),
Float(f64),
Numeric {
unscaled: i128,
scale: u16,
},
NumericBig(String),
String(String),
Timestamp {
micros: i64,
text: String,
},
Date {
days: i32,
text: String,
},
Bool(bool),
Null,
Vector(Vec<f32>),
TextArray(Vec<Option<String>>),
IntArray(Vec<Option<i32>>),
BigIntArray(Vec<Option<i64>>),
Interval {
months: i32,
days: i32,
micros: i64,
text: String,
},
}Variants§
Integer(i64)
Float(f64)
Numeric
Exact decimal literal — a bare 12.34-style token, kept as
unscaled / 10^scale so no precision or trailing-zero scale is lost
before it becomes a Value::Numeric. PG parses such literals as
numeric, not double precision. (Scientific/huge literals stay
Float.)
Fields
NumericBig(String)
v7.38 (read01, T3.C3) — an exact decimal literal whose mantissa overflows
i128 (kept as its source digit string, [-]digits[.digits]). Becomes a
Value::NumericBig at eval; previously such literals fell back to double.
String(String)
Timestamp
v7.38.8 — a temporal constant that has already been decoded.
Without these the only way to carry one through the AST was as
text, and a predicate comparing a timestamp column against a
literal then coerced that text back into a timestamp ONCE PER
ROW — 32 ns of the 52 a comparison cost, measured on a customer
profile. constfold produced text for the same reason: its exit
had nothing else to hand back.
text keeps the spelling so Display round-trips byte for byte,
the way Interval already does and for the same reason: this
node is printed in EXPLAIN, in dumps and in error messages, and
none of those should change because the value stopped being
carried as a string. The enum already holds a String and an
i128, so neither variant widens it.
Date
Days since the epoch Value::Date counts from. See
Literal::Timestamp.
Bool(bool)
Null
Vector(Vec<f32>)
pgvector-style array literal, e.g. [1, 2.5, -3].
TextArray(Vec<Option<String>>)
TEXT[] value carried through the prepared-bind path
(= ANY($1) has no column context to re-parse a {a,b}
text form, so the array rides the AST natively).
IntArray(Vec<Option<i32>>)
INT[] value carried through the prepared-bind path.
BigIntArray(Vec<Option<i64>>)
BIGINT[] value carried through the prepared-bind path.
Interval
INTERVAL '<n> <unit> [<n> <unit> ...]' — calendar-aware span.
Three independent dimensions: months (variable-length;
year/month), days (fixed 86400 seconds at non-DST, but
preserved as its own dimension so '1 day' ≠ '24 hours'
stays distinguishable), and micros (sub-day; can carry).
text keeps the original spelling so Display round-trips
byte-for-byte. v7.37.5 β added the days field for PG parity.