Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data Type

The library intentionally rejects conversions that could silently lose data. For example, reading a BIGINT column as i8 will return an error rather than truncating the value. This ensures data integrity and makes bugs easier to catch.

Widening conversions (e.g., reading SMALLINT as i64) are allowed.

Parameter Types (Rust to PostgreSQL)

Rust TypePostgreSQL TypeNotes
boolBOOL (BOOLEAN)
i8INT2 (SMALLINT)PostgreSQL has no 1-byte integer
i16INT2 (SMALLINT)
i32INT4 (INTEGER)
i64INT8 (BIGINT)
u8INT2 (SMALLINT)PostgreSQL has no unsigned types
u16INT4 (INTEGER)u16 max exceeds INT2 max
u32INT8 (BIGINT)u32 max exceeds INT4 max
u64INT8 (BIGINT)Overflow checked at runtime
f32FLOAT4 (REAL)
f64FLOAT8 (DOUBLE PRECISION)
&strTEXTAlso works with VARCHAR, CHAR, JSON, JSONB
StringTEXT
&[u8]BYTEA
Vec<u8>BYTEA
Option<T>Same as TNone encodes as NULL

Result Types (PostgreSQL to Rust)

PostgreSQL only has signed integer types. Decoding to unsigned Rust types (u8, u16, u32, u64) is not supported.

PostgreSQL TypeRust Types
BOOL (BOOLEAN)bool
INT2 (SMALLINT)i16, i32, i64
INT4 (INTEGER)i32, i64
INT8 (BIGINT)i64
FLOAT4 (REAL)f32, f64
FLOAT8 (DOUBLE PRECISION)f64
NUMERICf32, f64
TEXT, VARCHAR, CHAR(n), NAME&str, String
BYTEA&[u8], Vec<u8>
NULLOption<T>

Feature-Gated Types

Additional type support is available through feature flags.

with-chrono (chrono crate)

Rust TypePostgreSQL Type
chrono::NaiveDateDATE
chrono::NaiveTimeTIME
chrono::NaiveDateTimeTIMESTAMP, TIMESTAMPTZ
chrono::DateTime<Utc>TIMESTAMPTZ
PostgreSQL TypeRust Types
DATEchrono::NaiveDate
TIMEchrono::NaiveTime
TIMESTAMPchrono::NaiveDateTime
TIMESTAMPTZchrono::NaiveDateTime, chrono::DateTime<Utc>

with-time (time crate)

Rust TypePostgreSQL Type
time::DateDATE
time::TimeTIME
time::PrimitiveDateTimeTIMESTAMP, TIMESTAMPTZ
time::OffsetDateTimeTIMESTAMPTZ
PostgreSQL TypeRust Types
DATEtime::Date
TIMEtime::Time
TIMESTAMPtime::PrimitiveDateTime
TIMESTAMPTZtime::PrimitiveDateTime, time::OffsetDateTime

with-uuid (uuid crate)

Rust TypePostgreSQL Type
uuid::UuidUUID
PostgreSQL TypeRust Types
UUIDuuid::Uuid

with-rust-decimal (rust_decimal crate)

rust_decimal::Decimal uses 96-bit precision, not arbitrary precision like PostgreSQL’s NUMERIC.

Rust TypePostgreSQL Type
rust_decimal::DecimalNUMERIC
PostgreSQL TypeRust Types
NUMERICrust_decimal::Decimal