pub enum Expr {
Show 21 variants
Value(Value),
Field(FieldRef),
Binary {
left: Box<Expr>,
op: BinaryOp,
right: Box<Expr>,
},
Unary {
op: UnaryOp,
expr: Box<Expr>,
},
Func {
name: String,
args: Vec<Expr>,
},
Aggregate(AggregationDef),
Cast {
expr: Box<Expr>,
to_type: String,
},
Case(CaseDef),
Window(WindowDef),
Exists(Box<QueryStmt>),
SubQuery(Box<QueryStmt>),
ArraySubQuery(Box<QueryStmt>),
Collate {
expr: Box<Expr>,
collation: String,
},
JsonArray(Vec<Expr>),
JsonObject(Vec<(String, Expr)>),
JsonAgg {
expr: Box<Expr>,
distinct: bool,
filter: Option<Conditions>,
order_by: Option<Vec<OrderByDef>>,
},
StringAgg {
expr: Box<Expr>,
delimiter: String,
distinct: bool,
filter: Option<Conditions>,
order_by: Option<Vec<OrderByDef>>,
},
JsonPathText {
expr: Box<Expr>,
path: String,
},
Now,
Raw {
sql: String,
params: Vec<Value>,
},
Custom(Box<dyn CustomExpr>),
}Expand description
An expression in a SQL statement.
Variants§
Value(Value)
Literal value.
Field(FieldRef)
Column reference.
Binary
Binary operation: left op right.
Unary
Unary operation: -expr, NOT expr.
Func
Function call: name(args...).
Aggregate(AggregationDef)
Aggregate function: COUNT(expr), SUM(DISTINCT expr) FILTER (WHERE ...).
Cast
Type cast: expr::type (PG) or CAST(expr AS type).
Case(CaseDef)
CASE WHEN … THEN … ELSE … END.
Window(WindowDef)
Window function: expr OVER (PARTITION BY ... ORDER BY ... frame).
Exists(Box<QueryStmt>)
EXISTS (subquery).
SubQuery(Box<QueryStmt>)
Scalar subquery.
ArraySubQuery(Box<QueryStmt>)
ARRAY(subquery).
Collate
Collation override: expr COLLATE "name".
JsonArray(Vec<Expr>)
Build a JSON array: PG jsonb_build_array(...), SQLite json_array(...).
JsonObject(Vec<(String, Expr)>)
Build a JSON object: PG jsonb_build_object(k, v, ...), SQLite json_object(k, v, ...).
JsonAgg
Aggregate into JSON array: PG jsonb_agg(...), SQLite json_group_array(...).
StringAgg
Concatenate strings: PG string_agg(expr, delim), SQLite group_concat(expr, delim).
JsonPathText
JSON text extraction: expr->>'path' on both PG and SQLite.
Unlike -> (which returns JSON), ->> returns the value as text.
Now
Current timestamp: PG now(), SQLite datetime('now').
Raw
Raw SQL with parameters (escape hatch).
Custom(Box<dyn CustomExpr>)
User-defined expression (extension point).
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn collate(self, collation: impl Into<String>) -> Self
pub fn collate(self, collation: impl Into<String>) -> Self
Collation override: expr COLLATE "name".
Sourcepub fn json_array(items: Vec<Expr>) -> Self
pub fn json_array(items: Vec<Expr>) -> Self
Build a JSON array from expressions.
Sourcepub fn json_object(pairs: Vec<(impl Into<String>, Expr)>) -> Self
pub fn json_object(pairs: Vec<(impl Into<String>, Expr)>) -> Self
Build a JSON object from key-value pairs.
Sourcepub fn string_agg(expr: Expr, delimiter: impl Into<String>) -> Self
pub fn string_agg(expr: Expr, delimiter: impl Into<String>) -> Self
Concatenate strings with a delimiter.
Sourcepub fn json_path_text(expr: Expr, path: impl Into<String>) -> Self
pub fn json_path_text(expr: Expr, path: impl Into<String>) -> Self
JSON text extraction: expr->>'path'.