pub enum PgValue {
Show 25 variants
Null,
Bool(bool),
Int2(i16),
Int4(i32),
Int8(i64),
Float4(f32),
Float8(f64),
Text(String),
Bytes(Vec<u8>),
Json(String),
Jsonb(Vec<u8>),
Uuid([u8; 16]),
Date(i32),
Time(i64),
Timestamp(i64),
Timestamptz(i64),
Interval {
months: i32,
days: i32,
microseconds: i64,
},
Inet(String),
Numeric(String),
MacAddr([u8; 6]),
Point {
x: f64,
y: f64,
},
MacAddr8([u8; 8]),
Bit {
len: u32,
data: Vec<u8>,
},
Range(String),
Array(Vec<PgValue>),
}Expand description
A PostgreSQL value that can be used as a query parameter or read from a row.
Variants§
Null
Bool(bool)
Int2(i16)
Int4(i32)
Int8(i64)
Float4(f32)
Float8(f64)
Text(String)
Bytes(Vec<u8>)
Json(String)
Jsonb(Vec<u8>)
Uuid([u8; 16])
UUID stored as 16-byte array.
Date(i32)
Date: days since 2000-01-01 (PostgreSQL epoch).
Time(i64)
Time: microseconds since midnight.
Timestamp(i64)
Timestamp: microseconds since 2000-01-01 00:00:00 (PostgreSQL epoch).
Timestamptz(i64)
Timestamptz: microseconds since 2000-01-01 00:00:00 UTC.
Interval
Interval: months, days, microseconds.
Inet(String)
Network address (stored as text representation).
Numeric(String)
Numeric (stored as text representation for lossless precision).
MacAddr([u8; 6])
MAC address stored as 6 bytes.
Point
2D point: (x, y).
MacAddr8([u8; 8])
MAC address stored as 8 bytes (EUI-64).
Bit
Bit string: number of bits + packed bytes.
Range(String)
Range value (stored as text representation).
Examples: "[1,10)", "[2024-01-01,2024-12-31]", "empty".
Array(Vec<PgValue>)
Array of values (homogeneous).
Implementations§
Source§impl PgValue
impl PgValue
Sourcepub fn to_text_bytes(&self) -> Option<Vec<u8>>
pub fn to_text_bytes(&self) -> Option<Vec<u8>>
Encode this value as text-format bytes for use as a query parameter.
Sourcepub fn to_binary_bytes(&self) -> Option<Vec<u8>>
pub fn to_binary_bytes(&self) -> Option<Vec<u8>>
Encode this value as binary-format bytes for use as a query parameter.
Returns None for Null; Some(bytes) for everything else.
The binary format matches what PostgreSQL expects when the
parameter format code is 1 (binary).
Sourcepub fn prefers_binary(&self) -> bool
pub fn prefers_binary(&self) -> bool
Determine if this value should be sent as binary or text format.
Returns true for types that have an efficient binary encoding
(scalars, dates, etc.), false for types best sent as text
(arrays, numeric, inet).
Sourcepub fn from_text(type_oid: u32, data: &[u8]) -> Result<PgValue, PgError>
pub fn from_text(type_oid: u32, data: &[u8]) -> Result<PgValue, PgError>
Parse a text-format column value based on its type OID.