pub fn array<ST, T>(elements: T) -> array<ST, T>
Available on crate feature
postgres_backend
only.Expand description
Creates an ARRAY[e1, e2, ...]
or ARRAY(subselect)
expression.
The argument should be a tuple of expressions which can be represented by the same SQL type, or a subquery.
ยง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);
let ids = diesel::select(array(users.select(id)))
.first::<Vec<i32>>(connection)?;
assert_eq!(vec![1, 2], ids);