pub enum ScalarExpr {
Show 24 variants
Literal(Value),
Column(ColumnName),
Upper(Box<ScalarExpr>),
Lower(Box<ScalarExpr>),
Length(Box<ScalarExpr>),
Trim(Box<ScalarExpr>),
Concat(Vec<ScalarExpr>),
Abs(Box<ScalarExpr>),
Round(Box<ScalarExpr>),
RoundScale(Box<ScalarExpr>, i32),
Ceil(Box<ScalarExpr>),
Floor(Box<ScalarExpr>),
Coalesce(Vec<ScalarExpr>),
Nullif(Box<ScalarExpr>, Box<ScalarExpr>),
Cast(Box<ScalarExpr>, DataType),
Mod(Box<ScalarExpr>, Box<ScalarExpr>),
Power(Box<ScalarExpr>, Box<ScalarExpr>),
Sqrt(Box<ScalarExpr>),
Substring(Box<ScalarExpr>, SubstringRange),
Extract(DateField, Box<ScalarExpr>),
DateTrunc(DateField, Box<ScalarExpr>),
Now,
CurrentTimestamp,
CurrentDate,
}Expand description
A scalar expression that evaluates to a Value against a row.
Pressurecraft: pure over its inputs (no IO, no clocks, no RNG). Every variant’s evaluation is deterministic — same inputs produce the same output. VOPR-safe.
Variants§
Literal(Value)
Literal value.
Column(ColumnName)
Reference to a row column by name.
Upper(Box<ScalarExpr>)
UPPER(s) — ASCII-preserving uppercase via Unicode simple mapping.
Lower(Box<ScalarExpr>)
LOWER(s) — Unicode simple lowercase.
Length(Box<ScalarExpr>)
LENGTH(s) — character count (not byte count).
Trim(Box<ScalarExpr>)
TRIM(s) — strip ASCII whitespace from both ends.
Concat(Vec<ScalarExpr>)
CONCAT(a, b, …) — string concatenation. A NULL operand makes
the whole result NULL (PostgreSQL-compatible, differs from MySQL).
Abs(Box<ScalarExpr>)
ABS(n) — absolute value. Preserves the integer subtype when the
argument is an integer; returns Real for Real; returns
Decimal (same scale) for Decimal.
Round(Box<ScalarExpr>)
ROUND(x) — half-away-from-zero. For integers this is identity.
RoundScale(Box<ScalarExpr>, i32)
ROUND(x, scale) — round to scale decimal places. Only
meaningful for Real / Decimal operands; integer operands are
returned unchanged.
Ceil(Box<ScalarExpr>)
CEIL(x) / CEILING(x) — least integer >= x.
Floor(Box<ScalarExpr>)
FLOOR(x) — greatest integer <= x.
Coalesce(Vec<ScalarExpr>)
COALESCE(e1, e2, …) — first non-NULL argument, or NULL.
Nullif(Box<ScalarExpr>, Box<ScalarExpr>)
NULLIF(a, b) — NULL if a == b, otherwise a.
Cast(Box<ScalarExpr>, DataType)
CAST(x AS T) — convert x to the target DataType.
NULL in → NULL out for every target. Overflow on narrowing
integer casts and unparseable strings surface as
QueryError::TypeMismatch rather than silent truncation.
Mod(Box<ScalarExpr>, Box<ScalarExpr>)
MOD(a, b) — remainder of integer division. MOD(_, 0) → NULL
per Postgres semantics. AUDIT-2026-05 S3.7.
Power(Box<ScalarExpr>, Box<ScalarExpr>)
POWER(base, exp) — base^exp. Returns Real for any real
operand or non-integer exponent; integer-only inputs round-trip
through i64 and saturate on overflow. AUDIT-2026-05 S3.7.
Sqrt(Box<ScalarExpr>)
SQRT(x) — square root. Negative input returns
QueryError::DomainError. AUDIT-2026-05 S3.7.
Substring(Box<ScalarExpr>, SubstringRange)
SUBSTRING(s FROM start [FOR length]) with the
SubstringRange domain primitive carrying the SQL
1-based / negative-start semantics. AUDIT-2026-05 S3.8.
Extract(DateField, Box<ScalarExpr>)
EXTRACT(field FROM ts) — pull a calendar component from
a Date or Timestamp. Field set is the closed
DateField enum. AUDIT-2026-05 S3.7.
DateTrunc(DateField, Box<ScalarExpr>)
DATE_TRUNC('field', ts) — truncate timestamp to the
start of the field interval. Accepts only the truncatable
subset of DateField (Year/Month/Day/Hour/Minute/Second).
AUDIT-2026-05 S3.7.
Now
NOW() — current statement-stable timestamp. The plan-time
fold_time_constants pass replaces this variant with a
Literal(Timestamp) before execution; if the evaluator
ever sees a bare Now, that’s a planner bug and we panic
loudly. AUDIT-2026-05 S3.7.
CurrentTimestamp
CURRENT_TIMESTAMP — alias of NOW() per SQL standard;
distinct variant only because some test fixtures want to
pin the exact spelling. Same plan-time fold contract.
CurrentDate
CURRENT_DATE — current date, statement-stable. Plan-time
folded to Literal(Date(days_since_epoch)).
Trait Implementations§
Source§impl Clone for ScalarExpr
impl Clone for ScalarExpr
Source§fn clone(&self) -> ScalarExpr
fn clone(&self) -> ScalarExpr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more