Enum sql_parser::ast::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>)

Tuple Fields

0: Vec<Ident>

Identifier e.g. table name or column name

QualifiedWildcard(Vec<Ident>)

Tuple Fields

0: Vec<Ident>

Qualified wildcard, e.g. alias.* or schema.table.*.

FieldAccess

Fields

expr: Box<Expr<T>>
field: Ident

A field access, like (expr).foo.

WildcardAccess(Box<Expr<T>>)

Tuple Fields

0: 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

Fields

expr: Box<Expr<T>>

Boolean negation

And

Fields

left: Box<Expr<T>>
right: Box<Expr<T>>

Boolean and

Or

Fields

left: Box<Expr<T>>
right: Box<Expr<T>>

Boolean or

IsExpr

Fields

expr: Box<Expr<T>>
construct: IsExprConstruct
negated: bool

IS {NULL, TRUE, FALSE, UNKNOWN} expression

InList

Fields

expr: Box<Expr<T>>
list: Vec<Expr<T>>
negated: bool

[ NOT ] IN (val1, val2, ...)

InSubquery

Fields

expr: Box<Expr<T>>
subquery: Box<Query<T>>
negated: bool

[ NOT ] IN (SELECT ...)

Between

Fields

expr: Box<Expr<T>>
negated: bool
low: Box<Expr<T>>
high: Box<Expr<T>>

<expr> [ NOT ] BETWEEN <low> AND <high>

Op

Fields

op: Op
expr1: Box<Expr<T>>
expr2: Option<Box<Expr<T>>>

Unary or binary operator

Cast

Fields

expr: Box<Expr<T>>
data_type: DataType<T>

CAST an expression to a different data type e.g. CAST(foo AS VARCHAR(123))

Collate

Fields

expr: Box<Expr<T>>

expr COLLATE collation

HomogenizingFunction

Fields

exprs: Vec<Expr<T>>

COALESCE(, …) or GREATEST(, …) or LEAST(, …)

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

Fields

l_expr: Box<Expr<T>>
r_expr: Box<Expr<T>>

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>>)

Tuple Fields

0: Box<Expr<T>>

Nested expression e.g. (foo > bar) or (1)

Row

Fields

exprs: Vec<Expr<T>>

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

operand: Option<Box<Expr<T>>>
conditions: Vec<Expr<T>>
results: Vec<Expr<T>>
else_result: Option<Box<Expr<T>>>

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>>)

Tuple Fields

0: Box<Query<T>>

An exists expression EXISTS(SELECT ...), used in expressions like WHERE EXISTS (SELECT ...).

Subquery(Box<Query<T>>)

Tuple Fields

0: Box<Query<T>>

A parenthesized subquery (SELECT ...), used in expression like SELECT (subquery) AS x or WHERE (subquery) = x

AnySubquery

Fields

left: Box<Expr<T>>
op: Op
right: Box<Query<T>>

<expr> <op> ANY/SOME (<query>)

AnyExpr

Fields

left: Box<Expr<T>>
op: Op
right: Box<Expr<T>>

<expr> <op> ANY (<array_expr>)

AllSubquery

Fields

left: Box<Expr<T>>
op: Op
right: Box<Query<T>>

<expr> <op> ALL (<query>)

AllExpr

Fields

left: Box<Expr<T>>
op: Op
right: Box<Expr<T>>

<expr> <op> ALL (<array_expr>)

Array(Vec<Expr<T>>)

Tuple Fields

0: Vec<Expr<T>>

ARRAY[<expr>*]

List(Vec<Expr<T>>)

Tuple Fields

0: Vec<Expr<T>>

LIST[<expr>*]

ListSubquery(Box<Query<T>>)

Tuple Fields

0: Box<Query<T>>

SubscriptScalar

Fields

expr: Box<Expr<T>>
subscript: Box<Expr<T>>

<expr>[<expr>]

SubscriptSlice

Fields

expr: Box<Expr<T>>
positions: Vec<SubscriptPosition<T>>

<expr>[<expr>:<expr>(, <expr>?:<expr>?)*]

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

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.

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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