Expand description
§sql-values
sql-values holds the semantics of SQL values. It ports PostgreSQL’s own value rules (input, canonical output, order and arithmetic), each checked against PostgreSQL 18, and it reads the text forms PostgreSQL, MySQL and SQLite emit for scalar values, so every wire-text consumer decodes the same spelling to the same Rust value.
use sql_values::{IntervalError, parse_bool, parse_interval, parse_timestamp};
assert_eq!(parse_bool("t"), Some(true));
let span = parse_interval("1.5 days").unwrap();
assert_eq!(span.to_string(), "1 day 12:00:00");
assert_eq!(parse_interval("p1d"), Err(IntervalError::InvalidSyntax));
let at = parse_timestamp("2024-01-31 10:00:00").unwrap();
let month = parse_interval("1 mon").unwrap();
assert_eq!(month.add_to_timestamp(at).unwrap().to_string(), "2024-02-29 10:00:00");The crate supports no_std. Decimal parsing is available through the decimal feature, and serde derives for interval values through the serde feature.
Structs§
- Interval
Sum - The running state of PostgreSQL’s
sum(interval)andavg(interval). - Interval
Typmod - The modifier of an interval type, the fields it keeps and the fractional-second digits it
rounds to, where the default is plain
interval. - PgInterval
- A PostgreSQL
intervalas months, days and microseconds, equal, ordered and hashed by PostgreSQL’s span with a month as 30 days and a day as 24 hours.
Enums§
- Interval
Error - Why PostgreSQL refuses to read an interval or to compute one, one variant per message it raises.
- Interval
Fields - The fields an interval type keeps, as in
interval day to second. - Shift
Error - Why a timestamp or time shifted by an interval has no value here.
Functions§
- parse_
bool - Parse
t,f,1, or0as a boolean. - parse_
date - Parse a
YYYY-MM-DDdate with a year of four or more digits and PostgreSQL’s trailingBC. - parse_
decimal - Parse an arbitrary-precision decimal.
- parse_
f64 - Parse a 64-bit float, including PostgreSQL infinity and
NaNspellings. - parse_
i64 - Parse integer text with an optional leading sign.
- parse_
interval - Parse an interval as PostgreSQL 18’s
interval_inreads it under the defaultIntervalStyle. - parse_
interval_ typmod - Parse an interval literal of a restricted type as
interval '…' <fields>reads it, which differs from casting a text value to that type. - parse_
pg_ bytea_ hex - Parse PostgreSQL
\x-prefixed bytea hex with no intermediate allocation. - parse_
time - Parse
HH:MM:SS[.f]with one to nine fraction digits. - parse_
timestamp - Parse
YYYY-MM-DD HH:MM:SS[.f]with a space orTseparator, a year of four or more digits and PostgreSQL’s trailingBC. - parse_
timestamp_ tz - Parse a
parse_timestamplayout followed by aZ,±HH,±HHMM,±HH:MMor±HH:MM:SSoffset, then PostgreSQL’s optionalBC.