Expand description
Expression evaluator. Given a parsed Expr, a Row, and the row’s column
schema, produce a Value. v0.4 implements:
- literals
- column lookups (bare and qualified
t.col) - unary minus / NOT
- binary arithmetic, comparison, AND, OR
- numeric widening (
Int → BigInt → Float) at evaluation time - SQL three-valued logic for NULL:
- any arithmetic / comparison op with a NULL operand → NULL
TRUE OR NULL→ TRUE,FALSE OR NULL→ NULL,FALSE AND NULL→ FALSE,TRUE AND NULL→ NULL,NOT NULL→ NULL
v0.4 deliberately does not implement: function calls, string concatenation, IS NULL / IS NOT NULL, BETWEEN, IN, etc. Those come later.
Modules§
- compiled
- Compiled expressions — PG’s ExprState idea (cut 30, extracted
from
eval.rs; v7.32 perf knife D / architecture v2 P1).
Structs§
- Eval
Context - Resolution context for evaluating a single row.
table_aliasis the alias (or table name) callers should accept as the qualifier on a column ref — e.g.FROM users AS umakesu.namevalid and rejectsother.name. - Render
Style - Xact
View - v7.38 (T24) — the transaction-id surface PG’s
txid_*family exposes. SPG’s writer versions ARE its transaction ids (row_header::next_version), so no separate xid counter is needed — this is the bridge U22 was waiting on.
Enums§
- Date
Order - Date
Style Kind - Eval
Error - Interval
Style Kind - Sequence
Op - v7.17.0 — sequence operation requested by an Expr eval.
Functions§
- cast_
to_ vector - Parse a
Value::text("[1.0, 2.0, 3.0]")into aValue::vector(..). Mirrors pgvector’s'[..]'::vectorcast. NULL casts as NULL. - cast_
value - PG-style
expr::TYPEcoercion. NULL always casts as NULL. - days_
from_ civil - Inverse of
civil_from_days— converts (year, month, day) to days since 1970-01-01. Out-of-range months / days saturate. - decode_
tsquery_ external - v7.12.0 — decode PG external form
'foo' & 'bar' | !'baz'into aTsQueryAst. v7.12.0 supports the canonicalto_tsquerysurface: single-quoted lexemes,&/|/!, parens, and phrase<N>. Bare lexemes are accepted too. Fullplainto_tsquery/websearch_to_tsqueryarrive in v7.12.1. - decode_
tsvector_ external - v7.12.0 — decode PG external form
'word':1,2A 'other':3into aVec<TsLexeme>. Lexemes are sorted ascending byword(with duplicates merged on positions) so the output matches the engine invariant. Empty input yields an empty vector. - eval_
expr - format_
bigint_ array - v7.11.14 — render a BIGINT[] in PG’s external array form
(
{1,2,NULL}). - format_
bool_ array - v7.37.5 γ — render a BOOL[] in PG external form.
PG uses single-letter
t/ffor booleans (matching the scalar wire convention). - format_
bytea_ array - v7.37.5 γ — render a BYTEA[] in PG external form. Each
non-NULL element is
\\x<hex>(the PG hex output form) and is double-quoted because the leading backslash is a PG array escape character. - format_
bytea_ hex - format_
date - Render a
Date(days since epoch) asYYYY-MM-DD. Negative values for pre-1970 dates render with a leading-on the year. - format_
date_ array - v7.37.5 γ — render a DATE[] in PG external form. Each
non-NULL element is rendered as
YYYY-MM-DD. - format_
date_ array_ styled - Styled array renderers —
{elem,…}with per-element styled text. - format_
date_ styled format_dateunder a DateStyle. PG18 shapes: ISO2024-03-15· German15.03.2024· SQL03/15/2024(DMY15/03/2024) · Postgres03-15-2024(DMY15-03-2024). YMD field order affects only ISO-irrelevant styles’ INPUT; output falls back to the MDY arrangement (as PG does).- format_
float - v7.17.0 Phase 3.P0-35 — PG
moneycanonical text form, en_US PGfloat8out— the shortest round-trip decimal, rendered in scientific notation when the base-10 exponent is< -4or> 14(matching float.c’s choice), otherwise fixed. Learned from read01 float.c study: PG switches to1e+15/1e-05where SPG used to spell every digit (1000000000000000000000000000000). The exponent is read from Rust’s{:e}(exact — avoids log10 rounding at powers of ten) and reformatted to PG’se±NN(sign always shown, ≥ 2 digits). Infinities / NaN / signed zero matchfloat8outtoo. - format_
float_ array - v7.37.5 γ — render a FLOAT[] / DOUBLE PRECISION[] in PG external form. PG renders floats via the engine’s existing f64 → text path so this just calls Rust’s default Display.
- format_
float_ array_ styled - format_
float_ styled - PG
float8outunderextra_float_digits: >= 1 → shortest round-trip (format_float); <= 0 →%.{15+n}g. - format_
int_ array - v7.11.14 — render an INT[] in PG’s external array form
(
{1,2,NULL}). Integer payloads never need quoting. NULL elements use the literal tokenNULL. - format_
interval - Render an
Interval { months, days, micros }in a PG-ish shape. The output mirrorspsql’s text format: years/months from the months part, days from its own dimension (no carry from micros — this is the PG-canonical separation so'1 day'≠'24 hours'), HH:MM:SS[.frac] from micros. v7.37.5 β added thedaysparameter for PG byte-equal;microsmay still carry hours ≥ 24 (PG keeps the unnormalised form on the wire). - format_
interval_ array - v7.37.5 β-P4 — render an INTERVAL[] in PG’s external array form.
Each non-NULL element is double-quoted because interval text
contains spaces (
1 day) and colons (24:00:00) that would confuse the comma-separated parse:{"1 day","24:00:00",NULL}. Inner"doesn’t occur in interval text so no escaping is needed; backslashes likewise can’t appear. - format_
interval_ array_ styled - format_
interval_ styled format_intervalunder an IntervalStyle (PG18 differential truth):- format_
money - locale:
$N,NNN.CC, negative →-$1.23. Mirrors PG’scash_outforlc_monetary = 'en_US.UTF-8'. - format_
money_ array - v7.37.5 ζ-A — render a MONEY[] in PG external form. Each element
is the canonical
format_moneyoutput; the array wrapper is{...}with NULL elements as the literal tokenNULL. - format_
numeric - format_
numeric_ array - v7.37.5 γ — render a NUMERIC[] in PG external form.
- format_
numeric_ kind - Render a
Numeric { scaled, scale }as its decimal text form. Negativescaledprepends-to the absolute value’s digits; the integer / fractional split is by character count, padding the fractional side with leading zeros to exactlyscalechars. v7.38 (read01, T6) — render a NUMERIC honoring its special kind. Finite usesformat_numeric; the specials render PG’s full-word spellings. - format_
real - v7.38 (read01, T-float4) — PG
float4out: the f32 shortest round-trip, in fixed-point for decimal exponents in-4..=5and scientific otherwise (a tighter window than float8’s-4..=14, so12345678::real=1.2345678e+07while12345678::float8stays12345678). - format_
real_ styled - PG
float4outunderextra_float_digits: >= 1 → shortest round-trip (format_real); <= 0 →%.{6+n}g. - format_
smallint_ array - v7.37.5 γ — render a SMALLINT[] in PG external form.
- format_
text_ array - v7.10.9 — render a TEXT[] in PG’s external array form
(
{a,b,NULL}). Elements containing whitespace, commas, quotes, or braces get double-quoted with\\/\"escapes. NULL elements use the literal tokenNULL. Public so the wire layer can produce the canonical text-mode encoding. - format_
time - v7.17.0 Phase 3.P0-32 — PG
TIMEcanonical text formHH:MM:SS[.ffffff]. Mirrors PGtime_out. Trailing zeros in the fractional component are stripped —12:00:00.500000renders as12:00:00.5to match PG’s text output. - format_
timestamp - format_
timestamp_ array - v7.37.5 γ — render a TIMESTAMP[] (
with_tz=false) or TIMESTAMPTZ[] (with_tz=true) in PG external form. Each non-NULL element is double-quoted because the canonical timestamp text contains a space (2024-06-01 12:00:00) that would otherwise split on commas wrong. - format_
timestamp_ array_ styled - format_
timestamp_ styled format_timestampunder a DateStyle. German/SQL prepend their date form; Postgres style is the asctime-likeDow Mon DD HH:MM:SS[.f] YYYY(DMY:Dow DD Mon …).- format_
timestamptz - Render a
Timestamp(microseconds since epoch) asYYYY-MM-DD HH:MM:SS[.fff...]. Trailing-zero fractional digits are dropped; a whole-second value has no fractional part. v7.15.0 — PG-canonical TIMESTAMPTZ wire format. Storage is the same i64 microseconds UTC as TIMESTAMP, but the canonical PG text output appends the session’s UTC-offset suffix (+00for the default UTC session, the form pg_dump emits). Mailrs round-8 acceptance criterion:SELECT col FROM tstzshould round-trip to a literal that re-INSERTs without semantic drift. - format_
timestamptz_ at - v7.38 (T-tstz Phase 2) — render a UTC instant in a fixed-offset zone: shift
the wall clock by
offset_micros, then append PG’s offset suffix (+09,-05,+05:30,+00). Minutes are shown only when non-zero, matching PG. UTC (offset_micros == 0) reproduces the old+00output byte-for-byte. - format_
timestamptz_ styled format_timestamptzunder a DateStyle for the UTC session: ISO keeps the+00offset suffix; the other styles append the zone NAME (UTC), as PG does.- format_
timestamptz_ tz - v7.39 (tz epic) — the session-timezone-aware renderer: shift by the
per-value offset; ISO appends the numeric offset (
+09,+05:45), the other DateStyles append the zone designation — a named zone’s abbreviation (JST,EDT), a fixed offset’s numeric form, orUTC(all PG18-differential). - format_
timetz - v7.17.0 Phase 3.P0-34 — PG
TIMETZcanonical text formHH:MM:SS[.ffffff]±HH[:MM]. Mirrors PGtimetz_out. The offset uses±HHfor whole-hour offsets and±HH:MMfor sub-hour offsets (matching PG’s “minimal display” rule). - format_
tsquery - v7.12.0 — render a
tsqueryin PG’s external form. Operator precedence:!>&>|. Phrase distance shown as<N>. - format_
tsvector - v7.12.0 — render a
tsvectorin PG’s external form:'lex':1,2A 'word':3(single-quoted lexemes, optional:positions, optional weight letterA/B/C/Dper position). Lexemes already arrive sorted + deduped from the engine. Used by the wire layer (OID 3614) and by SELECT-text output. - format_
uuid_ array - v7.37.5 γ — render a UUID[] in PG external form. UUID text is the canonical lowercase 8-4-4-4-12 hyphenated form; no quoting needed (hex + dashes, no spaces / commas).
- gen_
random_ uuid_ bytes - v7.17.0 — generate a RFC 4122 v4 (random) UUID. Layout: 16
random bytes with the version nibble (high nibble of byte 6)
pinned to
0100(= 4) and the variant top bits (high two bits of byte 8) pinned to10— exactly what PG’sgen_random_uuid()and the historical uuid-osspuuid_generate_v4()produce. - parse_
date_ literal - Parse
YYYY-MM-DDinto aDate(days since Unix epoch). ReturnsNoneon shape / numeric failure; the engine surfaces that as aTypeMismatchwith the original text included. - parse_
date_ literal_ ordered - v7.39 (GUC knife 5) — DateOrder-aware date input. PG disambiguates
a three-field numeric date (
01/02/2024,02.01.2024,1/2/24) by the DateStyle field order: MDY reads month first (the default — so'01/02/2024'is Jan 2 even with no SET), DMY day first, YMD year first ('24/01/02', and'1/2/24'is 2001-02-24!). A two-digit year is < 70 → 20xx, >= 70 → 19xx. Field values that don’t fit the order error (MDY'13/02/2024'is out of range — PG does NOT auto-swap). ISO year-first four-digit forms parse the same under every order. - parse_
timestamp_ literal - Parse
YYYY-MM-DD[ HH:MM:SS[.ffffff]]into aTimestamp(microseconds since Unix epoch). The time portion is optional; missing → midnight. The fractional portion accepts 1–6 digits and pads with zeros to microseconds. - parse_
timestamp_ literal_ ordered - v7.39 (GUC knife 5) — DateOrder-aware timestamp input; the date
part follows
parse_date_literal_ordered’s disambiguation. - parse_
timestamp_ literal_ tz_ ordered - v7.39 (tz epic) — like
parse_timestamp_literal_orderedbut also reports whether the literal carried an explicit offset. A naive literal’s micros are the WALL clock (caller localises against the session zone for a timestamptz); an offset-bearing literal’s are UTC already. - parse_
vector_ text - Parse
"[1.0, 2.0, -3]"intoVec<f32>. ReturnsNoneon malformed input. - value_
to_ text - value_
to_ text_ styled - v7.39 (GUC knife 3) — the canonical renderer under a session
RenderStyle(DateStyle / IntervalStyle / extra_float_digits).value_to_textis the default-style shorthand. - value_
to_ text_ with_ fsp - v7.39 (round 425) — render a value the way a MySQL client expects a
column with a DECLARED fractional-seconds precision to look: EXACTLY
fspfractional digits, zero-padded (DATETIME(3)shows.250, and.000for a whole second), or none at all at precision 0. PG’s renderer trims trailing zeros, which is right for PG and wrong for MySQL — the stored instant is identical either way.
Type Aliases§
- Sequence
Resolver - v7.17.0 — sequence-mutating callback used by
apply_functionfornextval/currval/setval. Implemented by the engine to thread&mut Catalogaccess through an immutable&EvalContext.