Expand description
kevy-scalar — PG-canonical scalar function evaluation.
The function library behind kevy’s sql face (the V1 scalar
surface): SELECT lower('X')-shaped constant folding and the
query-card projection epilogue both call eval. Nothing here
ever runs inside a serving engine process — evaluation stays in
the sql face by design (Law 3), which is why this crate knows
nothing about kevy: it maps a function name and Scalar
arguments to a Scalar result, PG 18 semantics, and that is the
whole contract.
Semantics ground truth: the pg_regress-derived probe corpus
(bench/funcgate-corpus/). The tests in this crate are transcribed
from those files — where PG is surprising (floor toward −infinity,
trim strips a character SET not a substring, NULL propagates
through almost everything), the probe line is cited.
use kevy_scalar::{eval, Scalar};
let out = eval("lower", &[Scalar::Text("HeLLo".into())])?;
assert_eq!(out, Scalar::Text("hello".into()));Enums§
- Scalar
- A typed scalar value — the closed set the function library speaks.
- Scalar
Error - Why a call could not be evaluated.
Functions§
- binop
- Apply
a <op> bwhereopis one of+ - * /. - cmp_op
- A comparison operator (
=,<>,<,<=,>,>=) with strict NULL propagation. Same-type comparisons only, plus the int↔float numeric promotion; PG ordersfalse < true, text compares bytewise (C collation — the corpus subset’s semantics). - eval
- Evaluate
func(args…)with PG 18 semantics. - logic_
and - Three-valued
AND:falsedominates, otherwiseNULLif either side is unknown (PG:NULL AND false = false). - logic_
not - Three-valued
NOT:NOT NULLisNULL. - logic_
or - Three-valued
OR:truedominates (PG:NULL OR true = true). - parse_
date - Parse
YYYY-MM-DDinto days since the epoch. - parse_
interval - Parse a PG interval literal: whitespace-separated
<n> <unit>pairs (1 year 2 months,-3 days,90 minutes) into the three-component(months, days, micros). - parse_
pg_ bool - PG’s boolean input vocabulary (
boolin): case-insensitive, whitespace-trimmedt/f true/false y/n yes/no on/off 1/0. Anything else is a cast error (the caller reports it by name). - parse_
timestamp - Parse
YYYY-MM-DD[ HH:MM:SS[.ffffff]](aTseparator is accepted too) into epoch microseconds.Noneon anything malformed — the sql face refuses by name, this module never guesses. - render_
date YYYY-MM-DD.- render_
interval - PG’s interval output:
N year(s) N mon(s) N day(s) HH:MM:SS, each piece only when non-zero,00:00:00alone when everything is. The components render independently —1 day -12:00:00stays exactly that (probe 10). - render_
timestamp YYYY-MM-DD HH:MM:SS[.ffffff]— fraction only when non-zero.