pub enum PgValue {
Show 14 variants
Boolean(bool),
Integer(i64),
Numeric(PgNumeric),
Text(String),
Date(PgDate),
Timestamp(PgTimestamp),
Array(PgArray),
Jsonb(PgJsonb),
Uuid(PgUuid),
Bpchar(PgBpchar<'static>),
TimestampTz(PgTimestampTz),
Time(PgTime),
TimeTz(PgTimeTz),
Interval(PgInterval),
}Expand description
A known PostgreSQL value, equal, ordered and hashed by its type’s comparison operators.
An integer of every width and a numeric compare by value, as int48eq, or numeric_eq after
int8_numeric, compares them, so 4, 4::bigint and 4.00 are one value. A date compares
with a timestamp as date_cmp_timestamp does, equal to its midnight. A text compares by
its bytes, as under the C collation, and so do the strings in a jsonb. A uuid compares by
its bytes, as uuid_cmp does. Each remaining variant has a separate comparison family,
ordered after uuid in the order bpchar, timestamptz, time, timetz, interval.
Cross-family comparisons require the caller’s coercion and session settings.
Its Display uses DateStyle ISO, TimeZone UTC and IntervalStyle
postgres, as CastValue’s does.
extern crate alloc;
use alloc::collections::BTreeSet;
use sql_values::postgres::{InputContext, PgDate, PgNumeric, PgTimestamp, PgValue};
let four = PgValue::Numeric(PgNumeric::parse("4.00").unwrap());
assert_eq!(PgValue::Integer(4), four);
assert!(PgValue::Integer(5) > four);
assert_eq!(BTreeSet::from([PgValue::Integer(4), four]).len(), 1);
let day = PgValue::Date(PgDate::from_ymd(2026, 1, 1).unwrap());
let midnight = PgTimestamp::parse("2026-01-01 00:00", InputContext::new()).unwrap();
assert_eq!(day, PgValue::Timestamp(midnight));
assert!(PgValue::Text("B".into()) < PgValue::Text("a".into()));
assert!(PgValue::Boolean(true) < PgValue::Integer(0));
assert_eq!(PgValue::Boolean(true).to_string(), "t");Variants§
Boolean(bool)
A boolean, false before true.
Integer(i64)
A smallint, integer or bigint, whichever its width.
Numeric(PgNumeric)
A numeric.
Text(String)
A text or varchar.
Date(PgDate)
A date.
Timestamp(PgTimestamp)
A timestamp.
Array(PgArray)
An array of values over its dimensions, in row-major order.
Jsonb(PgJsonb)
A jsonb.
Uuid(PgUuid)
A uuid.
Bpchar(PgBpchar<'static>)
A char(n), compared without trailing spaces under the C collation.
TimestampTz(PgTimestampTz)
A timestamptz, compared by instant.
Time(PgTime)
A time.
TimeTz(PgTimeTz)
A timetz, compared by UTC time and then by offset west of UTC.
Interval(PgInterval)
An interval, compared with months as 30 days and days as 24 hours.
Implementations§
Source§impl PgValue
impl PgValue
Sourcepub fn into_cast_value(
self,
integer: IntegerType,
) -> Result<CastValue, CastError>
pub fn into_cast_value( self, integer: IntegerType, ) -> Result<CastValue, CastError>
The value as a CastValue, an integer held as integer.
§Errors
CastError::OutOfRange for an integer outside IntegerType::range.
use sql_values::postgres::{CastError, CastValue, IntegerType, BuiltinType, PgValue};
let value = || PgValue::Integer(40_000);
let held = value().into_cast_value(IntegerType::Integer);
assert_eq!(held, Ok(CastValue::Integer(40_000)));
assert_eq!(
value().into_cast_value(IntegerType::Smallint),
Err(CastError::OutOfRange(BuiltinType::Smallint)),
);
assert_eq!(PgValue::from(CastValue::Smallint(7)), PgValue::Integer(7));Sourcepub fn as_numeric(&self) -> Option<PgNumeric>
pub fn as_numeric(&self) -> Option<PgNumeric>
The numeric of an integer, as int8_numeric makes it, or a numeric itself.
Sourcepub fn as_timestamp(&self) -> Option<PgTimestamp>
pub fn as_timestamp(&self) -> Option<PgTimestamp>
The timestamp the value equals, a timestamp itself or a date’s midnight, which a date
from 294277-01-01 has none of.
use sql_values::postgres::{PgDate, PgValue};
let day = PgValue::Date(PgDate::from_ymd(2026, 1, 1).unwrap());
assert_eq!(day.as_timestamp().unwrap().to_string(), "2026-01-01 00:00:00");
let late = PgValue::Date(PgDate::from_ymd(294_277, 1, 1).unwrap());
assert_eq!(late.as_timestamp(), None);Sourcepub fn output(&self) -> Option<impl Display + '_>
pub fn output(&self) -> Option<impl Display + '_>
The type’s output function, or None when session settings decide its spelling.
use sql_values::postgres::{PgDate, PgValue};
let flag = PgValue::Boolean(false);
assert_eq!(flag.output().map(|output| output.to_string()).as_deref(), Some("f"));
assert!(PgValue::Date(PgDate::from_ymd(2026, 1, 1).unwrap()).output().is_none());