pub enum Expr {
Show 45 variants
Column {
table: Option<String>,
name: String,
quote_style: QuoteStyle,
table_quote_style: QuoteStyle,
},
Number(String),
StringLiteral(String),
Boolean(bool),
Null,
BinaryOp {
left: Box<Expr>,
op: BinaryOperator,
right: Box<Expr>,
},
UnaryOp {
op: UnaryOperator,
expr: Box<Expr>,
},
Function {
name: String,
args: Vec<Expr>,
distinct: bool,
filter: Option<Box<Expr>>,
over: Option<WindowSpec>,
},
Between {
expr: Box<Expr>,
low: Box<Expr>,
high: Box<Expr>,
negated: bool,
},
InList {
expr: Box<Expr>,
list: Vec<Expr>,
negated: bool,
},
InSubquery {
expr: Box<Expr>,
subquery: Box<Statement>,
negated: bool,
},
AnyOp {
expr: Box<Expr>,
op: BinaryOperator,
right: Box<Expr>,
},
AllOp {
expr: Box<Expr>,
op: BinaryOperator,
right: Box<Expr>,
},
IsNull {
expr: Box<Expr>,
negated: bool,
},
IsBool {
expr: Box<Expr>,
value: bool,
negated: bool,
},
Like {
expr: Box<Expr>,
pattern: Box<Expr>,
negated: bool,
escape: Option<Box<Expr>>,
},
ILike {
expr: Box<Expr>,
pattern: Box<Expr>,
negated: bool,
escape: Option<Box<Expr>>,
},
Case {
operand: Option<Box<Expr>>,
when_clauses: Vec<(Expr, Expr)>,
else_clause: Option<Box<Expr>>,
},
Nested(Box<Expr>),
Wildcard,
Subquery(Box<Statement>),
Exists {
subquery: Box<Statement>,
negated: bool,
},
Cast {
expr: Box<Expr>,
data_type: DataType,
},
TryCast {
expr: Box<Expr>,
data_type: DataType,
},
Extract {
field: DateTimeField,
expr: Box<Expr>,
},
Interval {
value: Box<Expr>,
unit: Option<DateTimeField>,
},
ArrayLiteral(Vec<Expr>),
Tuple(Vec<Expr>),
Coalesce(Vec<Expr>),
If {
condition: Box<Expr>,
true_val: Box<Expr>,
false_val: Option<Box<Expr>>,
},
NullIf {
expr: Box<Expr>,
else: Box<Expr>,
},
Collate {
expr: Box<Expr>,
collation: String,
},
Parameter(String),
TypeExpr(DataType),
QualifiedWildcard {
table: String,
},
Star,
Alias {
expr: Box<Expr>,
name: String,
},
ArrayIndex {
expr: Box<Expr>,
index: Box<Expr>,
},
JsonAccess {
expr: Box<Expr>,
path: Box<Expr>,
as_text: bool,
},
Lambda {
params: Vec<String>,
body: Box<Expr>,
},
Default,
Cube {
exprs: Vec<Expr>,
},
Rollup {
exprs: Vec<Expr>,
},
GroupingSets {
sets: Vec<Expr>,
},
TypedFunction {
func: TypedFunction,
filter: Option<Box<Expr>>,
over: Option<WindowSpec>,
},
}Expand description
An expression in SQL.
This enum is aligned with sqlglot’s Expression class hierarchy. Key additions over the basic implementation:
- Subquery, Exists, Cast, Extract, Window functions
- TypedString, Interval, Array/Struct constructors
- Postgres-style casting (
::)
Variants§
Column
A column reference, possibly qualified: [catalog.][schema.]table.column
Fields
quote_style: QuoteStyleHow the column name was quoted in the source SQL.
table_quote_style: QuoteStyleHow the table qualifier was quoted, if present.
Number(String)
A numeric literal.
StringLiteral(String)
A string literal.
Boolean(bool)
A boolean literal.
Null
NULL literal.
BinaryOp
A binary operation: left op right
UnaryOp
A unary operation: op expr
Function
A function call: name(args...) with optional DISTINCT, ORDER BY, etc.
Fields
over: Option<WindowSpec>OVER window specification for window functions
Between
expr BETWEEN low AND high
InList
expr IN (list...) or expr IN (subquery)
InSubquery
expr IN (SELECT ...)
AnyOp
expr op ANY(subexpr) — PostgreSQL array/subquery comparison
AllOp
expr op ALL(subexpr) — PostgreSQL array/subquery comparison
IsNull
expr IS [NOT] NULL
IsBool
expr IS [NOT] TRUE / expr IS [NOT] FALSE
Like
expr [NOT] LIKE pattern [ESCAPE escape_char]
ILike
expr [NOT] ILIKE pattern [ESCAPE escape_char] (case-insensitive LIKE)
Case
CASE [operand] WHEN ... THEN ... ELSE ... END
Nested(Box<Expr>)
A parenthesized sub-expression.
Wildcard
A wildcard * used in contexts like COUNT(*).
Subquery(Box<Statement>)
A scalar subquery: (SELECT ...)
Exists
EXISTS (SELECT ...)
Cast
CAST(expr AS type) or expr::type (PostgreSQL)
TryCast
TRY_CAST(expr AS type)
Extract
EXTRACT(field FROM expr)
Interval
INTERVAL 'value' unit
ArrayLiteral(Vec<Expr>)
Array literal: ARRAY[1, 2, 3] or [1, 2, 3]
Tuple(Vec<Expr>)
Struct literal / row constructor: (1, 'a', true)
Coalesce(Vec<Expr>)
COALESCE(a, b, c)
If
IF(condition, true_val, false_val) (MySQL, BigQuery)
NullIf
NULLIF(a, b)
Collate
expr COLLATE collation
Parameter(String)
Parameter / placeholder: $1, ?, :name
TypeExpr(DataType)
A type expression used in DDL contexts or CAST
QualifiedWildcard
table.* in expression context
Star
Star expression *
Alias
Alias expression: expr AS name
ArrayIndex
Array access: expr[index]
JsonAccess
JSON access: expr->key or expr->>key
Lambda
Lambda expression: x -> x + 1
Default
DEFAULT keyword in INSERT/UPDATE contexts
Cube
CUBE(a, b, ...) in GROUP BY clause
Rollup
ROLLUP(a, b, ...) in GROUP BY clause
GroupingSets
GROUPING SETS ((a, b), (c), ...) in GROUP BY clause
TypedFunction
A typed function expression with semantic awareness. Enables per-function, per-dialect code generation and transpilation.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn walk<F>(&self, visitor: &mut F)
pub fn walk<F>(&self, visitor: &mut F)
Recursively walk this expression tree, calling visitor on each node.
If visitor returns false, children of that node are not visited.
Sourcepub fn find<F>(&self, predicate: &F) -> Option<&Expr>
pub fn find<F>(&self, predicate: &F) -> Option<&Expr>
Find the first expression matching the predicate.
Sourcepub fn find_all<F>(&self, predicate: &F) -> Vec<&Expr>
pub fn find_all<F>(&self, predicate: &F) -> Vec<&Expr>
Find all expressions matching the predicate.
Sourcepub fn transform<F>(self, func: &F) -> Expr
pub fn transform<F>(self, func: &F) -> Expr
Transform this expression tree by applying a function to each node. The function can return a new expression to replace the current one.
Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Check whether this expression is a literal value (number, string, bool, null).