Trait sqlx::postgres::PgHasArrayType

source ยท
pub trait PgHasArrayType {
    // Required method
    fn array_type_info() -> PgTypeInfo;

    // Provided method
    fn array_compatible(ty: &PgTypeInfo) -> bool { ... }
}
Available on crate feature postgres only.
Expand description

Provides information necessary to encode and decode Postgres arrays as compatible Rust types.

Implementing this trait for some type T enables relevant Type,Encode and Decode impls for Vec<T>, &[T] (slices), [T; N] (arrays), etc.

ยงNote: #[derive(sqlx::Type)]

If you have the postgres feature enabled, #[derive(sqlx::Type)] will also generate an impl of this trait for your type if your wrapper is marked #[sqlx(transparent)]:

โ“˜
#[derive(sqlx::Type)]
#[sqlx(transparent)]
struct UserId(i64);

let user_ids: Vec<UserId> = sqlx::query_scalar("select '{ 123, 456 }'::int8[]")
   .fetch(&mut pg_connection)
   .await?;

However, this may cause an error if the type being wrapped does not implement PgHasArrayType, e.g. Vec itself, because we donโ€™t currently support multidimensional arrays:

โ“˜
#[derive(sqlx::Type)] // ERROR: `Vec<i64>` does not implement `PgHasArrayType`
#[sqlx(transparent)]
struct UserIds(Vec<i64>);

To remedy this, add #[sqlx(no_pg_array)], which disables the generation of the PgHasArrayType impl:

โ“˜
#[derive(sqlx::Type)]
#[sqlx(transparent, no_pg_array)]
struct UserIds(Vec<i64>);

See the documentation of Type for more details.

Required Methodsยง

Provided Methodsยง

Object Safetyยง

This trait is not object safe.

Implementations on Foreign Typesยง

sourceยง

impl PgHasArrayType for &str

sourceยง

impl PgHasArrayType for &[u8]

sourceยง

impl PgHasArrayType for Cow<'_, str>

sourceยง

impl PgHasArrayType for IpAddr

sourceยง

impl PgHasArrayType for bool

sourceยง

impl PgHasArrayType for f32

sourceยง

impl PgHasArrayType for f64

sourceยง

impl PgHasArrayType for i8

sourceยง

impl PgHasArrayType for i16

sourceยง

impl PgHasArrayType for i32

sourceยง

impl PgHasArrayType for i64

sourceยง

impl PgHasArrayType for u8

sourceยง

impl PgHasArrayType for Box<str>

sourceยง

impl PgHasArrayType for Box<[u8]>

sourceยง

impl PgHasArrayType for String

sourceยง

impl PgHasArrayType for Vec<u8>

sourceยง

impl PgHasArrayType for NonZero<i16>

sourceยง

impl PgHasArrayType for NonZero<i32>

sourceยง

impl PgHasArrayType for NonZero<i64>

sourceยง

impl PgHasArrayType for Duration

sourceยง

impl PgHasArrayType for TimeDelta

sourceยง

impl PgHasArrayType for Duration

sourceยง

impl<T1> PgHasArrayType for (T1,)

sourceยง

impl<T1, T2> PgHasArrayType for (T1, T2)

sourceยง

impl<T1, T2, T3> PgHasArrayType for (T1, T2, T3)

sourceยง

impl<T1, T2, T3, T4> PgHasArrayType for (T1, T2, T3, T4)

sourceยง

impl<T1, T2, T3, T4, T5> PgHasArrayType for (T1, T2, T3, T4, T5)

sourceยง

impl<T1, T2, T3, T4, T5, T6> PgHasArrayType for (T1, T2, T3, T4, T5, T6)

sourceยง

impl<T1, T2, T3, T4, T5, T6, T7> PgHasArrayType for (T1, T2, T3, T4, T5, T6, T7)

sourceยง

impl<T1, T2, T3, T4, T5, T6, T7, T8> PgHasArrayType for (T1, T2, T3, T4, T5, T6, T7, T8)

sourceยง

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> PgHasArrayType for (T1, T2, T3, T4, T5, T6, T7, T8, T9)

sourceยง

impl<T> PgHasArrayType for Option<T>
where T: PgHasArrayType,

sourceยง

impl<T> PgHasArrayType for &T
where T: PgHasArrayType,

sourceยง

impl<const N: usize> PgHasArrayType for [u8; N]

Implementorsยง

sourceยง

impl PgHasArrayType for Value

sourceยง

impl PgHasArrayType for IpNetwork

sourceยง

impl PgHasArrayType for PgCube

sourceยง

impl PgHasArrayType for NaiveDate

sourceยง

impl PgHasArrayType for NaiveDateTime

sourceยง

impl PgHasArrayType for NaiveTime

sourceยง

impl PgHasArrayType for MacAddress

sourceยง

impl PgHasArrayType for BigDecimal

sourceยง

impl PgHasArrayType for BitVec

sourceยง

impl PgHasArrayType for Decimal

sourceยง

impl PgHasArrayType for RawValue

sourceยง

impl PgHasArrayType for Uuid

sourceยง

impl PgHasArrayType for Date

sourceยง

impl PgHasArrayType for OffsetDateTime

sourceยง

impl PgHasArrayType for PrimitiveDateTime

sourceยง

impl PgHasArrayType for Time

sourceยง

impl PgHasArrayType for Oid

sourceยง

impl PgHasArrayType for PgCiText

sourceยง

impl PgHasArrayType for PgInterval

sourceยง

impl PgHasArrayType for PgLTree

sourceยง

impl PgHasArrayType for PgMoney

sourceยง

impl PgHasArrayType for PgRange<i32>

sourceยง

impl PgHasArrayType for PgRange<i64>

sourceยง

impl PgHasArrayType for PgRange<NaiveDate>

sourceยง

impl PgHasArrayType for PgRange<NaiveDateTime>

sourceยง

impl PgHasArrayType for PgRange<BigDecimal>

sourceยง

impl PgHasArrayType for PgRange<Decimal>

sourceยง

impl PgHasArrayType for PgRange<Date>

sourceยง

impl PgHasArrayType for PgRange<OffsetDateTime>

sourceยง

impl PgHasArrayType for PgRange<PrimitiveDateTime>

sourceยง

impl<T> PgHasArrayType for Json<T>

sourceยง

impl<T> PgHasArrayType for Text<T>

sourceยง

impl<Time, Offset> PgHasArrayType for PgTimeTz<Time, Offset>

sourceยง

impl<Tz> PgHasArrayType for DateTime<Tz>
where Tz: TimeZone,

sourceยง

impl<Tz> PgHasArrayType for PgRange<DateTime<Tz>>
where Tz: TimeZone,