Skip to main content

PgValue

Enum PgValue 

Source
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.

Fields

§months: i32
§days: i32
§microseconds: i64
§

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).

Fields

§

MacAddr8([u8; 8])

MAC address stored as 8 bytes (EUI-64).

§

Bit

Bit string: number of bits + packed bytes.

Fields

§len: u32
§data: Vec<u8>
§

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

Source

pub fn to_text_bytes(&self) -> Option<Vec<u8>>

Encode this value as text-format bytes for use as a query parameter.

Source

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).

Source

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).

Source

pub fn from_text(type_oid: u32, data: &[u8]) -> Result<PgValue, PgError>

Parse a text-format column value based on its type OID.

Source

pub fn from_binary(type_oid: u32, data: &[u8]) -> Result<PgValue, PgError>

Parse a binary-format column value based on its type OID.

Source

pub fn as_i32(&self) -> Option<i32>

Try to extract as i32.

Source

pub fn as_i64(&self) -> Option<i64>

Try to extract as i64.

Source

pub fn as_str(&self) -> Option<&str>

Try to extract as &str.

Source

pub fn as_bool(&self) -> Option<bool>

Try to extract as bool.

Source

pub fn as_f64(&self) -> Option<f64>

Try to extract as f64.

Source

pub fn is_null(&self) -> bool

Returns true if this is a Null value.

Trait Implementations§

Source§

impl Clone for PgValue

Source§

fn clone(&self) -> PgValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PgValue

Source§

fn eq(&self, other: &PgValue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToSql for PgValue

Source§

fn to_sql(&self) -> PgValue

Convert this value to a PgValue for use as a query parameter.
Source§

fn type_oid(&self) -> u32

The PostgreSQL type OID this value maps to (0 = let the server decide).
Source§

impl StructuralPartialEq for PgValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToParam for T
where T: ToSql,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.