Enum sql_parser::ast::defs::expr::Expr [−][src]
pub enum Expr<T: AstInfo> {
Show 33 variants
Identifier(Vec<Ident>),
QualifiedWildcard(Vec<Ident>),
FieldAccess {
expr: Box<Expr<T>>,
field: Ident,
},
WildcardAccess(Box<Expr<T>>),
Parameter(usize),
Not {
expr: Box<Expr<T>>,
},
And {
left: Box<Expr<T>>,
right: Box<Expr<T>>,
},
Or {
left: Box<Expr<T>>,
right: Box<Expr<T>>,
},
IsExpr {
expr: Box<Expr<T>>,
construct: IsExprConstruct,
negated: bool,
},
InList {
expr: Box<Expr<T>>,
list: Vec<Expr<T>>,
negated: bool,
},
InSubquery {
expr: Box<Expr<T>>,
subquery: Box<Query<T>>,
negated: bool,
},
Between {
expr: Box<Expr<T>>,
negated: bool,
low: Box<Expr<T>>,
high: Box<Expr<T>>,
},
Op {
op: Op,
expr1: Box<Expr<T>>,
expr2: Option<Box<Expr<T>>>,
},
Cast {
expr: Box<Expr<T>>,
data_type: DataType<T>,
},
Collate {
expr: Box<Expr<T>>,
collation: UnresolvedObjectName,
},
HomogenizingFunction {
function: HomogenizingFunction,
exprs: Vec<Expr<T>>,
},
NullIf {
l_expr: Box<Expr<T>>,
r_expr: Box<Expr<T>>,
},
Nested(Box<Expr<T>>),
Row {
exprs: Vec<Expr<T>>,
},
Value(Value),
Function(Function<T>),
Case {
operand: Option<Box<Expr<T>>>,
conditions: Vec<Expr<T>>,
results: Vec<Expr<T>>,
else_result: Option<Box<Expr<T>>>,
},
Exists(Box<Query<T>>),
Subquery(Box<Query<T>>),
AnySubquery {
left: Box<Expr<T>>,
op: Op,
right: Box<Query<T>>,
},
AnyExpr {
left: Box<Expr<T>>,
op: Op,
right: Box<Expr<T>>,
},
AllSubquery {
left: Box<Expr<T>>,
op: Op,
right: Box<Query<T>>,
},
AllExpr {
left: Box<Expr<T>>,
op: Op,
right: Box<Expr<T>>,
},
Array(Vec<Expr<T>>),
List(Vec<Expr<T>>),
ListSubquery(Box<Query<T>>),
SubscriptScalar {
expr: Box<Expr<T>>,
subscript: Box<Expr<T>>,
},
SubscriptSlice {
expr: Box<Expr<T>>,
positions: Vec<SubscriptPosition<T>>,
},
}
Expand description
An SQL expression of any type.
The parser does not distinguish between expressions of different types
(e.g. boolean vs string), so the caller must handle expressions of
inappropriate type, like WHERE 1
or SELECT 1=1
, as necessary.
Variants
Identifier(Vec<Ident>)
Identifier e.g. table name or column name
QualifiedWildcard(Vec<Ident>)
Qualified wildcard, e.g. alias.*
or schema.table.*
.
FieldAccess
A field access, like (expr).foo
.
WildcardAccess(Box<Expr<T>>)
A wildcard field access, like (expr).*
.
Note that this is different from QualifiedWildcard
in that the
wildcard access occurs on an arbitrary expression, rather than a
qualified name. The distinction is important for PostgreSQL
compatibility.
Parameter(usize)
Tuple Fields
0: usize
A positional parameter, e.g., $1
or $42
Not
Boolean negation
And
Boolean and
Or
Boolean or
IsExpr
IS {NULL, TRUE, FALSE, UNKNOWN}
expression
InList
[ NOT ] IN (val1, val2, ...)
InSubquery
[ NOT ] IN (SELECT ...)
Between
<expr> [ NOT ] BETWEEN <low> AND <high>
Op
Unary or binary operator
Cast
CAST an expression to a different data type e.g. CAST(foo AS VARCHAR(123))
Collate
expr COLLATE collation
HomogenizingFunction
COALESCE(
While COALESCE/GREATEST/LEAST have the same syntax as a function call, their semantics are extremely unusual, and are better captured with a dedicated AST node.
NullIf
NULLIF(expr, expr)
While NULLIF has the same syntax as a function call, it is not evaluated as a function within Postgres.
Nested(Box<Expr<T>>)
Nested expression e.g. (foo > bar)
or (1)
Row
A row constructor like ROW(<expr>...)
or (<expr>, <expr>...)
.
Value(Value)
Tuple Fields
0: Value
A literal value, such as string, number, date or NULL
Function(Function<T>)
Tuple Fields
0: Function<T>
Scalar function call e.g. LEFT(foo, 5)
Case
Fields
CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END
Note we only recognize a complete single expression as <condition>
,
not < 0
nor 1, 2, 3
as allowed in a <simple when clause>
per
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#simple-when-clause
Exists(Box<Query<T>>)
An exists expression EXISTS(SELECT ...)
, used in expressions like
WHERE EXISTS (SELECT ...)
.
Subquery(Box<Query<T>>)
A parenthesized subquery (SELECT ...)
, used in expression like
SELECT (subquery) AS x
or WHERE (subquery) = x
AnySubquery
<expr> <op> ANY/SOME (<query>)
AnyExpr
<expr> <op> ANY (<array_expr>)
AllSubquery
<expr> <op> ALL (<query>)
AllExpr
<expr> <op> ALL (<array_expr>)
Array(Vec<Expr<T>>)
ARRAY[<expr>*]
List(Vec<Expr<T>>)
LIST[<expr>*]
ListSubquery(Box<Query<T>>)
SubscriptScalar
<expr>[<expr>]
SubscriptSlice
<expr>[<expr>:<expr>(, <expr>?:<expr>?)*]
Implementations
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Expr<T> where
<T as AstInfo>::Id: RefUnwindSafe,
<T as AstInfo>::ObjectName: RefUnwindSafe,
impl<T> Unpin for Expr<T> where
<T as AstInfo>::ObjectName: Unpin,
impl<T> UnwindSafe for Expr<T> where
<T as AstInfo>::Id: UnwindSafe,
<T as AstInfo>::ObjectName: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Formats an object with the “alternative” format ({:#}
) and returns it.
Compare self to key
and return true
if they are equal.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more