Skip to main content

ArrayOperand

Trait ArrayOperand 

Source
pub trait ArrayOperand<Rhs> { }
Expand description

SQL type pairs that the array operators (@>, <@, &&) accept.

Self is the SQL type of the left operand and Rhs the SQL type of the right operand. The pair is accepted when:

  • both are arrays, Array<T> and Array<U>, and T is Compatible with U (so int4[] works with int8[], but not with text[]);
  • the left side is an array and the right side is a Placeholder or untyped SQL (Any);
  • the left side is untyped SQL (Any), which accepts any right side.

Anything else, such as a single value or a plain Vec, is rejected at compile time. Wrap a Rust list in PgArray to bind it as one array.

§Type safety

ⓘ
use drizzle_core::expr::raw_non_null;
use drizzle_postgres::expr::array_contains;
use drizzle_postgres::values::PostgresValue;
use drizzle_types::{Array, postgres::types::Text};

let tags = raw_non_null::<PostgresValue, Array<Text>>("tags");
// A single value is not an array: wrap it as `PgArray(vec!["rust"])`.
let _ = array_contains(tags, "rust");
ⓘ
use drizzle_core::expr::raw_non_null;
use drizzle_postgres::expr::{array_overlaps, PgArray};
use drizzle_postgres::values::PostgresValue;
use drizzle_types::{Array, postgres::types::Int4};

let ids = raw_non_null::<PostgresValue, Array<Int4>>("ids");
// `int4[]` cannot be compared with `text[]`.
let _ = array_overlaps(ids, PgArray(vec!["1"]));

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, U: DataType> ArrayOperand<Array<U>> for Array<T>
where T: Compatible<U> + DataType,

Source§

impl<T: DataType> ArrayOperand<Any> for Array<T>

Source§

impl<T: DataType> ArrayOperand<Placeholder> for Array<T>

Implementors§

Source§

impl<R> ArrayOperand<R> for Any