Function diesel::pg::expression::dsl::array

source ·
pub fn array<ST, T>(elements: T) -> ArrayLiteral<T::Expression, ST>where
    T: AsExpressionList<ST>,
Available on crate feature postgres_backend only.
Expand description

Creates an ARRAY[...] expression.

The argument should be a tuple of expressions which can be represented by the same SQL type.

Examples

let ints = diesel::select(array::<Integer, _>((1, 2)))
    .get_result::<Vec<i32>>(connection)?;
assert_eq!(vec![1, 2], ints);

let ids = users.select(array((id, id * 2)))
    .get_results::<Vec<i32>>(connection)?;
let expected = vec![
    vec![1, 2],
    vec![2, 4],
];
assert_eq!(expected, ids);