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.
Rust Type PostgreSQL Type Notes
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 T None encodes as NULL
PostgreSQL only has signed integer types. Decoding to unsigned Rust types (u8, u16, u32, u64) is not supported.
PostgreSQL Type Rust 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>
Additional type support is available through feature flags.
Rust Type PostgreSQL Type
chrono::NaiveDateDATE
chrono::NaiveTimeTIME
chrono::NaiveDateTimeTIMESTAMP, TIMESTAMPTZ
chrono::DateTime<Utc>TIMESTAMPTZ
PostgreSQL Type Rust Types
DATEchrono::NaiveDate
TIMEchrono::NaiveTime
TIMESTAMPchrono::NaiveDateTime
TIMESTAMPTZchrono::NaiveDateTime, chrono::DateTime<Utc>
Rust Type PostgreSQL Type
time::DateDATE
time::TimeTIME
time::PrimitiveDateTimeTIMESTAMP, TIMESTAMPTZ
time::OffsetDateTimeTIMESTAMPTZ
PostgreSQL Type Rust Types
DATEtime::Date
TIMEtime::Time
TIMESTAMPtime::PrimitiveDateTime
TIMESTAMPTZtime::PrimitiveDateTime, time::OffsetDateTime
Rust Type PostgreSQL Type
uuid::UuidUUID
PostgreSQL Type Rust Types
UUIDuuid::Uuid
rust_decimal::Decimal uses 96-bit precision, not arbitrary precision like PostgreSQL’s NUMERIC.
Rust Type PostgreSQL Type
rust_decimal::DecimalNUMERIC
PostgreSQL Type Rust Types
NUMERICrust_decimal::Decimal