pub enum Expr {
Show 33 variants Identifier(Ident), CompoundIdentifier(Vec<Ident>), IsNull(Box<Expr>), IsNotNull(Box<Expr>), IsDistinctFrom(Box<Expr>, Box<Expr>), IsNotDistinctFrom(Box<Expr>, Box<Expr>), InList { expr: Box<Expr>, list: Vec<Expr>, negated: bool, }, InSubquery { expr: Box<Expr>, subquery: Box<Query>, negated: bool, }, InUnnest { expr: Box<Expr>, array_expr: Box<Expr>, negated: bool, }, Between { expr: Box<Expr>, negated: bool, low: Box<Expr>, high: Box<Expr>, }, BinaryOp { left: Box<Expr>, op: BinaryOperator, right: Box<Expr>, }, UnaryOp { op: UnaryOperator, expr: Box<Expr>, }, Cast { expr: Box<Expr>, data_type: DataType, }, TryCast { expr: Box<Expr>, data_type: DataType, }, Extract { field: DateTimeField, expr: Box<Expr>, }, Substring { expr: Box<Expr>, substring_from: Option<Box<Expr>>, substring_for: Option<Box<Expr>>, }, Trim { expr: Box<Expr>, trim_where: Option<(TrimWhereField, Box<Expr>)>, }, Collate { expr: Box<Expr>, collation: ObjectName, }, Nested(Box<Expr>), Value(Value), TypedString { data_type: DataType, value: String, }, MapAccess { column: Box<Expr>, keys: Vec<Expr>, }, Function(Function), Case { operand: Option<Box<Expr>>, conditions: Vec<Expr>, results: Vec<Expr>, else_result: Option<Box<Expr>>, }, Exists(Box<Query>), Subquery(Box<Query>), ListAgg(ListAgg), GroupingSets(Vec<Vec<Expr>>), Cube(Vec<Vec<Expr>>), Rollup(Vec<Vec<Expr>>), Tuple(Vec<Expr>), ArrayIndex { obj: Box<Expr>, indexs: Vec<Expr>, }, Array(Array),
}
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(Ident)

Identifier e.g. table name or column name

CompoundIdentifier(Vec<Ident>)

Multi-part identifier, e.g. table_alias.column or schema.table.col

IsNull(Box<Expr>)

IS NULL operator

IsNotNull(Box<Expr>)

IS NOT NULL operator

IsDistinctFrom(Box<Expr>, Box<Expr>)

IS DISTINCT FROM operator

IsNotDistinctFrom(Box<Expr>, Box<Expr>)

IS NOT DISTINCT FROM operator

InList

Fields

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

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

InSubquery

Fields

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

[ NOT ] IN (SELECT ...)

InUnnest

Fields

expr: Box<Expr>
array_expr: Box<Expr>
negated: bool

[ NOT ] IN UNNEST(array_expression)

Between

Fields

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

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

BinaryOp

Fields

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

Binary operation e.g. 1 + 1 or foo > bar

UnaryOp

Fields

expr: Box<Expr>

Unary operation e.g. NOT foo

Cast

Fields

expr: Box<Expr>
data_type: DataType

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

TryCast

Fields

expr: Box<Expr>
data_type: DataType

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

Extract

Fields

expr: Box<Expr>

EXTRACT(DateTimeField FROM )

Substring

Fields

expr: Box<Expr>
substring_from: Option<Box<Expr>>
substring_for: Option<Box<Expr>>

SUBSTRING( [FROM ] [FOR ])

Trim

Fields

expr: Box<Expr>

TRIM([BOTH | LEADING | TRAILING] [FROM ])
Or
TRIM()

Collate

Fields

expr: Box<Expr>
collation: ObjectName

expr COLLATE collation

Nested(Box<Expr>)

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

Value(Value)

A literal value, such as string, number, date or NULL

TypedString

Fields

data_type: DataType
value: String

A constant of form <data_type> 'value'. This can represent ANSI SQL DATE, TIME, and TIMESTAMP literals (such as DATE '2020-01-01'), as well as constants of other types (a non-standard PostgreSQL extension).

MapAccess

Fields

column: Box<Expr>
keys: Vec<Expr>

Function(Function)

Scalar function call e.g. LEFT(foo, 5)

Case

Fields

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

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

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

Subquery(Box<Query>)

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

ListAgg(ListAgg)

The LISTAGG function SELECT LISTAGG(...) WITHIN GROUP (ORDER BY ...)

GroupingSets(Vec<Vec<Expr>>)

The GROUPING SETS expr.

Cube(Vec<Vec<Expr>>)

The CUBE expr.

Rollup(Vec<Vec<Expr>>)

The ROLLUP expr.

Tuple(Vec<Expr>)

ROW / TUPLE a single value, such as SELECT (1, 2)

ArrayIndex

Fields

obj: Box<Expr>
indexs: Vec<Expr>

An array index expression e.g. (ARRAY[1, 2])[1] or (current_schemas(FALSE))[1]

Array(Array)

An array expression e.g. ARRAY[1, 2]

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.