pub trait PgArrayExpressionMethods: Sized + Expression {
// Provided methods
fn overlaps_with<T>(
self,
other: T,
) -> Grouped<OverlapsWith<Self, <T as AsExpression<Self::SqlType>>::Expression>>
where Self::SqlType: SqlType,
T: AsExpression<Self::SqlType> { ... }
fn contains<T>(
self,
other: T,
) -> Grouped<Contains<Self, <T as AsExpression<Self::SqlType>>::Expression>>
where Self::SqlType: SqlType,
T: AsExpression<Self::SqlType> { ... }
fn is_contained_by<T>(
self,
other: T,
) -> Grouped<IsContainedBy<Self, <T as AsExpression<Self::SqlType>>::Expression>>
where Self::SqlType: SqlType,
T: AsExpression<Self::SqlType> { ... }
fn index<T>(
self,
other: T,
) -> ArrayIndex<Self, <T as AsExpression<Integer>>::Expression>
where Self::SqlType: SqlType,
T: AsExpression<Integer> { ... }
fn concat<T>(
self,
other: T,
) -> Grouped<Concat<Self, <T as AsExpression<Self::SqlType>>::Expression>>
where Self::SqlType: SqlType,
T: AsExpression<Self::SqlType> { ... }
}
Expand description
PostgreSQL specific methods present on array expressions.
Provided Methods§
sourcefn overlaps_with<T>(
self,
other: T,
) -> Grouped<OverlapsWith<Self, <T as AsExpression<Self::SqlType>>::Expression>>
fn overlaps_with<T>( self, other: T, ) -> Grouped<OverlapsWith<Self, <T as AsExpression<Self::SqlType>>::Expression>>
Creates a PostgreSQL &&
expression.
This operator returns whether two arrays have common elements.
§Example
diesel::insert_into(posts)
.values(&vec![
tags.eq(vec!["cool", "awesome"]),
tags.eq(vec!["awesome", "great"]),
tags.eq(vec!["cool", "great"]),
])
.execute(conn)?;
let data = posts.select(id)
.filter(tags.overlaps_with(vec!["horrid", "cool"]))
.load::<i32>(conn)?;
assert_eq!(vec![1, 3], data);
let data = posts.select(id)
.filter(tags.overlaps_with(vec!["cool", "great"]))
.load::<i32>(conn)?;
assert_eq!(vec![1, 2, 3], data);
let data = posts.select(id)
.filter(tags.overlaps_with(vec!["horrid"]))
.load::<i32>(conn)?;
assert!(data.is_empty());
sourcefn contains<T>(
self,
other: T,
) -> Grouped<Contains<Self, <T as AsExpression<Self::SqlType>>::Expression>>
fn contains<T>( self, other: T, ) -> Grouped<Contains<Self, <T as AsExpression<Self::SqlType>>::Expression>>
Creates a PostgreSQL @>
expression.
This operator returns whether an array contains another array.
§Example
diesel::insert_into(posts)
.values(tags.eq(vec!["cool", "awesome"]))
.execute(conn)?;
let cool_posts = posts.select(id)
.filter(tags.contains(vec!["cool"]))
.load::<i32>(conn)?;
assert_eq!(vec![1], cool_posts);
let amazing_posts = posts.select(id)
.filter(tags.contains(vec!["cool", "amazing"]))
.load::<i32>(conn)?;
assert!(amazing_posts.is_empty());
sourcefn is_contained_by<T>(
self,
other: T,
) -> Grouped<IsContainedBy<Self, <T as AsExpression<Self::SqlType>>::Expression>>
fn is_contained_by<T>( self, other: T, ) -> Grouped<IsContainedBy<Self, <T as AsExpression<Self::SqlType>>::Expression>>
Creates a PostgreSQL <@
expression.
This operator returns whether an array is contained by another array.
foo.contains(bar)
is the same as bar.is_contained_by(foo)
§Example
diesel::insert_into(posts)
.values(tags.eq(vec!["cool", "awesome"]))
.execute(conn)?;
let data = posts.select(id)
.filter(tags.is_contained_by(vec!["cool", "awesome", "amazing"]))
.load::<i32>(conn)?;
assert_eq!(vec![1], data);
let data = posts.select(id)
.filter(tags.is_contained_by(vec!["cool"]))
.load::<i32>(conn)?;
assert!(data.is_empty());
sourcefn index<T>(
self,
other: T,
) -> ArrayIndex<Self, <T as AsExpression<Integer>>::Expression>
fn index<T>( self, other: T, ) -> ArrayIndex<Self, <T as AsExpression<Integer>>::Expression>
Indexes a PostgreSQL array.
This operator indexes in to an array to access a single element.
Note that PostgreSQL arrays are 1-indexed, so foo.index(1)
is the
first element in the array.
§Example
diesel::insert_into(posts)
.values(&vec![
tags.eq(vec!["cool", "awesome"]),
tags.eq(vec!["splendid", "marvellous"]),
])
.execute(conn)?;
let data = posts.select(tags.index(id))
.load::<String>(conn)?;
assert_eq!(vec!["cool", "marvellous"], data);
let data = posts.select(id)
.filter(tags.index(1).eq("splendid"))
.load::<i32>(conn)?;
assert_eq!(vec![2], data);
sourcefn concat<T>(
self,
other: T,
) -> Grouped<Concat<Self, <T as AsExpression<Self::SqlType>>::Expression>>
fn concat<T>( self, other: T, ) -> Grouped<Concat<Self, <T as AsExpression<Self::SqlType>>::Expression>>
Creates a PostgreSQL ||
expression.
This operator concatenates two Array values and returns Array value
§Example
diesel::insert_into(posts)
.values(tags.eq(vec!["cool", "awesome"]))
.execute(conn)?;
let res = posts.select(tags.concat(vec!["amazing"])).load::<Vec<String>>(conn)?;
let expected_tags = vec!["cool", "awesome", "amazing"];
assert_eq!(expected_tags, res[0]);
Object Safety§
This trait is not object safe.