pub trait PgExpr: ExprTrait {
// Provided methods
fn concatenate<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
fn concat<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
fn matches<T>(self, expr: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
fn contains<T>(self, expr: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
fn contained<T>(self, expr: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
fn ilike<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr { ... }
fn not_ilike<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr { ... }
fn get_json_field<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
fn cast_json_field<T>(self, right: T) -> SimpleExpr
where T: Into<SimpleExpr> { ... }
}
Available on crate feature
backend-postgres
only.Provided Methodsยง
sourcefn concatenate<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn concatenate<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Express an postgres concatenate (||
) expression.
ยงExamples
use sea_query::{extension::postgres::PgExpr, tests_cfg::*, *};
let query = Query::select()
.columns([Font::Name, Font::Variant, Font::Language])
.from(Font::Table)
.and_where(Expr::val("a").concatenate("b").concat("c").concat("d"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "name", "variant", "language" FROM "font" WHERE 'a' || 'b' || 'c' || 'd'"#
);
sourcefn concat<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn concat<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Alias of PgExpr::concatenate
sourcefn matches<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn matches<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Express an postgres fulltext search matches (@@
) expression.
ยงExamples
use sea_query::{*, tests_cfg::*, extension::postgres::PgExpr};
let query = Query::select()
.columns([Font::Name, Font::Variant, Font::Language])
.from(Font::Table)
.and_where(Expr::val("a & b").matches("a b"))
.and_where(Expr::col(Font::Name).matches("a b"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "name", "variant", "language" FROM "font" WHERE 'a & b' @@ 'a b' AND "name" @@ 'a b'"#
);
sourcefn contains<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn contains<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Express an postgres fulltext search contains (@>
) expression.
ยงExamples
use sea_query::{*, tests_cfg::*, extension::postgres::PgExpr};
let query = Query::select()
.columns([Font::Name, Font::Variant, Font::Language])
.from(Font::Table)
.and_where(Expr::val("a & b").contains("a b"))
.and_where(Expr::col(Font::Name).contains("a b"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "name", "variant", "language" FROM "font" WHERE 'a & b' @> 'a b' AND "name" @> 'a b'"#
);
sourcefn contained<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn contained<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Express an postgres fulltext search contained (<@
) expression.
ยงExamples
use sea_query::{*, tests_cfg::*, extension::postgres::PgExpr};
let query = Query::select()
.columns([Font::Name, Font::Variant, Font::Language])
.from(Font::Table)
.and_where(Expr::val("a & b").contained("a b"))
.and_where(Expr::col(Font::Name).contained("a b"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "name", "variant", "language" FROM "font" WHERE 'a & b' <@ 'a b' AND "name" <@ 'a b'"#
);
sourcefn ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
Express a ILIKE
expression.
ยงExamples
use sea_query::{*, tests_cfg::*, extension::postgres::PgExpr};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::Character)).ilike("Ours'%"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" ILIKE E'Ours\'%'"#
);
sourcefn not_ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn not_ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
Express a NOT ILIKE
expression
sourcefn get_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn get_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Express a postgres retrieves JSON field as JSON value (->
).
ยงExamples
use sea_query::{extension::postgres::PgExpr, tests_cfg::*, *};
let query = Query::select()
.column(Font::Variant)
.from(Font::Table)
.and_where(Expr::col(Font::Variant).get_json_field("a"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "variant" FROM "font" WHERE "variant" -> 'a'"#
);
sourcefn cast_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn cast_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
Express a postgres retrieves JSON field and casts it to an appropriate SQL type (->>
).
ยงExamples
use sea_query::{extension::postgres::PgExpr, tests_cfg::*, *};
let query = Query::select()
.column(Font::Variant)
.from(Font::Table)
.and_where(Expr::col(Font::Variant).cast_json_field("a"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "variant" FROM "font" WHERE "variant" ->> 'a'"#
);
Dyn Compatibilityยง
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.