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 index_nullable<T>(
self,
other: T,
) -> ArrayIndex<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
where Self::SqlType: SqlType,
T: AsExpression<Nullable<Integer>> { ... }
fn slice<T1, T2>(
self,
start: T1,
end: T2,
) -> ArraySlice<Self, <T1 as AsExpression<Integer>>::Expression, <T2 as AsExpression<Integer>>::Expression>
where Self::SqlType: SqlType,
T1: AsExpression<Integer>,
T2: AsExpression<Integer> { ... }
fn slice_nullable<T1, T2>(
self,
start: T1,
end: T2,
) -> ArraySlice<Self, <T1 as AsExpression<Nullable<Integer>>>::Expression, <T2 as AsExpression<Nullable<Integer>>>::Expression>
where Self::SqlType: SqlType,
T1: AsExpression<Nullable<Integer>>,
T2: AsExpression<Nullable<Integer>> { ... }
fn slice_from<T>(
self,
start: T,
) -> ArraySliceFrom<Self, <T as AsExpression<Integer>>::Expression>
where Self::SqlType: SqlType,
T: AsExpression<Integer> { ... }
fn slice_from_nullable<T>(
self,
start: T,
) -> ArraySliceFrom<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
where Self::SqlType: SqlType,
T: AsExpression<Nullable<Integer>> { ... }
fn slice_to<T>(
self,
end: T,
) -> ArraySliceTo<Self, <T as AsExpression<Integer>>::Expression>
where Self::SqlType: SqlType,
T: AsExpression<Integer> { ... }
fn slice_to_nullable<T>(
self,
end: T,
) -> ArraySliceTo<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
where Self::SqlType: SqlType,
T: AsExpression<Nullable<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 index_nullable<T>(
self,
other: T,
) -> ArrayIndex<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
fn index_nullable<T>( self, other: T, ) -> ArrayIndex<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
Indexes a PostgreSQL array. This is the same as PgArrayExpressionMethods::index
but takes a nullable expression for the parameter.
This operator indexes in to an array to access a single element.
Note that PostgreSQL arrays are 1-indexed, so foo.index_nullable(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_nullable(id.nullable()))
.load::<Option<String>>(conn)?;
assert_eq!(vec![Some("cool".to_string()), Some("marvellous".to_string())], data);
let data = posts.select(id)
.filter(tags.index_nullable(1).eq(Some("splendid")))
.load::<i32>(conn)?;
assert_eq!(vec![2], data);Sourcefn slice<T1, T2>(
self,
start: T1,
end: T2,
) -> ArraySlice<Self, <T1 as AsExpression<Integer>>::Expression, <T2 as AsExpression<Integer>>::Expression>
fn slice<T1, T2>( self, start: T1, end: T2, ) -> ArraySlice<Self, <T1 as AsExpression<Integer>>::Expression, <T2 as AsExpression<Integer>>::Expression>
Indexes a PostgreSQL array with the slice delimited by the given indexes.
This operator indexes in to an array to access a subslice of the array.
Note that PostgreSQL array slices are 1-indexed and inclusive, so
foo.slice(1, 3) returns the first three elements 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.slice(id, id))
.load::<Vec<String>>(conn)?;
assert_eq!(vec![vec!["cool"], vec!["marvellous"]], data);
let data = posts.select(id)
.filter(tags.slice(1, 2).eq(vec!["splendid", "marvellous"]))
.load::<i32>(conn)?;
assert_eq!(vec![2], data);Sourcefn slice_nullable<T1, T2>(
self,
start: T1,
end: T2,
) -> ArraySlice<Self, <T1 as AsExpression<Nullable<Integer>>>::Expression, <T2 as AsExpression<Nullable<Integer>>>::Expression>where
Self::SqlType: SqlType,
T1: AsExpression<Nullable<Integer>>,
T2: AsExpression<Nullable<Integer>>,
fn slice_nullable<T1, T2>(
self,
start: T1,
end: T2,
) -> ArraySlice<Self, <T1 as AsExpression<Nullable<Integer>>>::Expression, <T2 as AsExpression<Nullable<Integer>>>::Expression>where
Self::SqlType: SqlType,
T1: AsExpression<Nullable<Integer>>,
T2: AsExpression<Nullable<Integer>>,
Indexes a PostgreSQL array with the slice delimited by the given indexes.
This is the same as PgArrayExpressionMethods::slice
but takes nullable expressions for the parameters.
This operator indexes in to an array to access a subslice of the array.
Note that PostgreSQL array slices are 1-indexed and inclusive, so
foo.slice_nullable(1, 3) returns the first three elements 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.slice_nullable(id.nullable(), id.nullable()))
.load::<Option<Vec<String>>>(conn)?;
assert_eq!(vec![Some(vec!["cool".to_string()]), Some(vec!["marvellous".to_string()])], data);
let data = posts.select(id)
.filter(tags.slice_nullable(1, 2).eq(Some(vec!["splendid", "marvellous"])))
.load::<i32>(conn)?;
assert_eq!(vec![2], data);Sourcefn slice_from<T>(
self,
start: T,
) -> ArraySliceFrom<Self, <T as AsExpression<Integer>>::Expression>
fn slice_from<T>( self, start: T, ) -> ArraySliceFrom<Self, <T as AsExpression<Integer>>::Expression>
Indexes a PostgreSQL array with the slice starting from the given index.
This operator indexes in to an array to access a subslice of the array,
Note that PostgreSQL array slices are 1-indexed, so
foo.slice_from(1) returns all the elements 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.slice_from(id))
.load::<Vec<String>>(conn)?;
assert_eq!(vec![vec!["cool", "awesome"], vec!["marvellous"]], data);
let data = posts.select(id)
.filter(tags.slice_from(2).eq(vec!["marvellous"]))
.load::<i32>(conn)?;
assert_eq!(vec![2], data);Sourcefn slice_from_nullable<T>(
self,
start: T,
) -> ArraySliceFrom<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
fn slice_from_nullable<T>( self, start: T, ) -> ArraySliceFrom<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
Indexes a PostgreSQL array with the slice starting from the given index.
This is the same as PgArrayExpressionMethods::slice_from
but takes a nullable expression for the parameter.
This operator indexes in to an array to access a subslice of the array,
Note that PostgreSQL array slices are 1-indexed, so
foo.slice_from_nullable(1) returns all the elements 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.slice_from_nullable(id.nullable()))
.load::<Option<Vec<String>>>(conn)?;
assert_eq!(vec![Some(vec!["cool".to_string(), "awesome".to_string()]), Some(vec!["marvellous".to_string()])], data);
let data = posts.select(id)
.filter(tags.slice_from_nullable(2).eq(Some(vec!["marvellous"])))
.load::<i32>(conn)?;
assert_eq!(vec![2], data);Sourcefn slice_to<T>(
self,
end: T,
) -> ArraySliceTo<Self, <T as AsExpression<Integer>>::Expression>
fn slice_to<T>( self, end: T, ) -> ArraySliceTo<Self, <T as AsExpression<Integer>>::Expression>
Indexes a PostgreSQL array with the slice ending with the given index.
This operator indexes in to an array to access a subslice of the array,
Note that PostgreSQL array slices are 1-indexed, so
foo.slice_to(3) returns the first three elements 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.slice_to(id))
.load::<Vec<String>>(conn)?;
assert_eq!(vec![vec!["cool"], vec!["splendid", "marvellous"]], data);
let data = posts.select(id)
.filter(tags.slice_to(1).eq(vec!["cool"]))
.load::<i32>(conn)?;
assert_eq!(vec![1], data);Sourcefn slice_to_nullable<T>(
self,
end: T,
) -> ArraySliceTo<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
fn slice_to_nullable<T>( self, end: T, ) -> ArraySliceTo<Self, <T as AsExpression<Nullable<Integer>>>::Expression>
Indexes a PostgreSQL array with the slice ending with the given index.
This is the same as PgArrayExpressionMethods::slice_to
but takes a nullable expression for the parameter.
This operator indexes in to an array to access a subslice of the array,
Note that PostgreSQL array slices are 1-indexed, so
foo.slice_to_nullable(3) returns the first three elements 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.slice_to_nullable(id.nullable()))
.load::<Option<Vec<String>>>(conn)?;
assert_eq!(vec![Some(vec!["cool".to_string()]), Some(vec!["splendid".to_string(), "marvellous".to_string()])], data);
let data = posts.select(id)
.filter(tags.slice_to_nullable(1).eq(Some(vec!["cool"])))
.load::<i32>(conn)?;
assert_eq!(vec![1], 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]);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".