Enum sqlparser::ast::Expr

source ·
pub enum Expr {
Show 65 variants Identifier(Ident), CompoundIdentifier(Vec<Ident>), JsonAccess { left: Box<Expr>, operator: JsonOperator, right: Box<Expr>, }, CompositeAccess { expr: Box<Expr>, key: Ident, }, IsFalse(Box<Expr>), IsNotFalse(Box<Expr>), IsTrue(Box<Expr>), IsNotTrue(Box<Expr>), IsNull(Box<Expr>), IsNotNull(Box<Expr>), IsUnknown(Box<Expr>), IsNotUnknown(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>, }, Like { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<char>, }, ILike { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<char>, }, SimilarTo { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<char>, }, RLike { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, regexp: bool, }, AnyOp { left: Box<Expr>, compare_op: BinaryOperator, right: Box<Expr>, }, AllOp { left: Box<Expr>, compare_op: BinaryOperator, right: Box<Expr>, }, UnaryOp { op: UnaryOperator, expr: Box<Expr>, }, Convert { expr: Box<Expr>, data_type: Option<DataType>, charset: Option<ObjectName>, target_before_value: bool, }, Cast { expr: Box<Expr>, data_type: DataType, format: Option<CastFormat>, }, TryCast { expr: Box<Expr>, data_type: DataType, format: Option<CastFormat>, }, SafeCast { expr: Box<Expr>, data_type: DataType, format: Option<CastFormat>, }, AtTimeZone { timestamp: Box<Expr>, time_zone: String, }, Extract { field: DateTimeField, expr: Box<Expr>, }, Ceil { expr: Box<Expr>, field: DateTimeField, }, Floor { expr: Box<Expr>, field: DateTimeField, }, Position { expr: Box<Expr>, in: Box<Expr>, }, Substring { expr: Box<Expr>, substring_from: Option<Box<Expr>>, substring_for: Option<Box<Expr>>, special: bool, }, Trim { expr: Box<Expr>, trim_where: Option<TrimWhereField>, trim_what: Option<Box<Expr>>, trim_characters: Option<Vec<Expr>>, }, Overlay { expr: Box<Expr>, overlay_what: Box<Expr>, overlay_from: Box<Expr>, overlay_for: Option<Box<Expr>>, }, Collate { expr: Box<Expr>, collation: ObjectName, }, Nested(Box<Expr>), Value(Value), IntroducedString { introducer: String, value: Value, }, TypedString { data_type: DataType, value: String, }, MapAccess { column: Box<Expr>, keys: Vec<Expr>, }, Function(Function), AggregateExpressionWithFilter { expr: Box<Expr>, filter: Box<Expr>, }, Case { operand: Option<Box<Expr>>, conditions: Vec<Expr>, results: Vec<Expr>, else_result: Option<Box<Expr>>, }, Exists { subquery: Box<Query>, negated: bool, }, Subquery(Box<Query>), ArraySubquery(Box<Query>), ListAgg(ListAgg), ArrayAgg(ArrayAgg), GroupingSets(Vec<Vec<Expr>>), Cube(Vec<Vec<Expr>>), Rollup(Vec<Vec<Expr>>), Tuple(Vec<Expr>), Struct { values: Vec<Expr>, fields: Vec<StructField>, }, Named { expr: Box<Expr>, name: Ident, }, ArrayIndex { obj: Box<Expr>, indexes: Vec<Expr>, }, Array(Array), Interval(Interval), MatchAgainst { columns: Vec<Ident>, match_value: Value, opt_search_modifier: Option<SearchModifier>, }, Wildcard, QualifiedWildcard(ObjectName), OuterJoin(Box<Expr>),
}
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

§

JsonAccess

Fields

§left: Box<Expr>
§operator: JsonOperator
§right: Box<Expr>

JSON access (postgres) eg: data->‘tags’

§

CompositeAccess

Fields

§expr: Box<Expr>
§key: Ident

CompositeAccess (postgres) eg: SELECT (information_schema._pg_expandarray(array[‘i’,‘i’])).n

§

IsFalse(Box<Expr>)

IS FALSE operator

§

IsNotFalse(Box<Expr>)

IS NOT FALSE operator

§

IsTrue(Box<Expr>)

IS TRUE operator

§

IsNotTrue(Box<Expr>)

IS NOT TRUE operator

§

IsNull(Box<Expr>)

IS NULL operator

§

IsNotNull(Box<Expr>)

IS NOT NULL operator

§

IsUnknown(Box<Expr>)

IS UNKNOWN operator

§

IsNotUnknown(Box<Expr>)

IS NOT UNKNOWN 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

§

Like

Fields

§negated: bool
§expr: Box<Expr>
§pattern: Box<Expr>
§escape_char: Option<char>

[NOT] LIKE <pattern> [ESCAPE <escape_character>]

§

ILike

Fields

§negated: bool
§expr: Box<Expr>
§pattern: Box<Expr>
§escape_char: Option<char>

ILIKE (case-insensitive LIKE)

§

SimilarTo

Fields

§negated: bool
§expr: Box<Expr>
§pattern: Box<Expr>
§escape_char: Option<char>

SIMILAR TO regex

§

RLike

Fields

§negated: bool
§expr: Box<Expr>
§pattern: Box<Expr>
§regexp: bool

MySQL: RLIKE regex or REGEXP regex

§

AnyOp

Fields

§left: Box<Expr>
§compare_op: BinaryOperator
§right: Box<Expr>

ANY operation e.g. foo > ANY(bar), comparison operator is one of [=, >, <, =>, =<, !=]

§

AllOp

Fields

§left: Box<Expr>
§compare_op: BinaryOperator
§right: Box<Expr>

ALL operation e.g. foo > ALL(bar), comparison operator is one of [=, >, <, =>, =<, !=]

§

UnaryOp

Fields

§expr: Box<Expr>

Unary operation e.g. NOT foo

§

Convert

Fields

§expr: Box<Expr>

The expression to convert

§data_type: Option<DataType>

The target data type

§charset: Option<ObjectName>

The target character encoding

§target_before_value: bool

whether the target comes before the expr (MSSQL syntax)

CONVERT a value to a different data type or character encoding. e.g. CONVERT(foo USING utf8mb4)

§

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

§

SafeCast

Fields

§expr: Box<Expr>
§data_type: DataType

SAFE_CAST an expression to a different data type e.g. SAFE_CAST(foo AS FLOAT64)

§

AtTimeZone

Fields

§timestamp: Box<Expr>
§time_zone: String

AT a timestamp to a different timezone e.g. FROM_UNIXTIME(0) AT TIME ZONE 'UTC-06:00'

§

Extract

Fields

§expr: Box<Expr>

Extract a field from a timestamp e.g. EXTRACT(MONTH FROM foo)

Syntax:

EXTRACT(DateTimeField FROM <expr>)
§

Ceil

Fields

§expr: Box<Expr>
CEIL(<expr> [TO DateTimeField])
§

Floor

Fields

§expr: Box<Expr>
FLOOR(<expr> [TO DateTimeField])
§

Position

Fields

§expr: Box<Expr>
§in: Box<Expr>
POSITION(<expr> in <expr>)
§

Substring

Fields

§expr: Box<Expr>
§substring_from: Option<Box<Expr>>
§substring_for: Option<Box<Expr>>
§special: bool
SUBSTRING(<expr> [FROM <expr>] [FOR <expr>])
§

Trim

Fields

§expr: Box<Expr>
§trim_what: Option<Box<Expr>>
§trim_characters: Option<Vec<Expr>>
TRIM([BOTH | LEADING | TRAILING] [<expr> FROM] <expr>)
TRIM(<expr>)
TRIM(<expr>, [, characters]) -- only Snowflake or Bigquery
§

Overlay

Fields

§expr: Box<Expr>
§overlay_what: Box<Expr>
§overlay_from: Box<Expr>
§overlay_for: Option<Box<Expr>>
OVERLAY(<expr> PLACING <expr> FROM <expr>[ FOR <expr> ]
§

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

§

IntroducedString

Fields

§introducer: String
§value: Value
§

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>

Access a map-like object by field (e.g. column['field'] or column[4] Note that depending on the dialect, struct like accesses may be parsed as ArrayIndex or MapAccess https://clickhouse.com/docs/en/sql-reference/data-types/map/

§

Function(Function)

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

§

AggregateExpressionWithFilter

Fields

§expr: Box<Expr>
§filter: Box<Expr>

Aggregate function with filter

§

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

Fields

§subquery: Box<Query>
§negated: bool

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

§

Subquery(Box<Query>)

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

§

ArraySubquery(Box<Query>)

An array subquery constructor, e.g. SELECT ARRAY(SELECT 1 UNION SELECT 2)

§

ListAgg(ListAgg)

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

§

ArrayAgg(ArrayAgg)

The ARRAY_AGG function SELECT ARRAY_AGG(... 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)

§

Struct

Fields

§values: Vec<Expr>

Struct values.

§fields: Vec<StructField>

Struct field definitions.

BigQuery specific Struct literal expression 1 Syntax:

STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
§

Named

Fields

§expr: Box<Expr>
§name: Ident

BigQuery specific: An named expression in a typeless struct 1

Syntax

1 AS A
§

ArrayIndex

Fields

§obj: Box<Expr>
§indexes: 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]

§

Interval(Interval)

An interval expression e.g. INTERVAL '1' YEAR

§

MatchAgainst

Fields

§columns: Vec<Ident>

(<col>, <col>, ...).

§match_value: Value

<expr>.

§opt_search_modifier: Option<SearchModifier>

<search modifier>

MySQL specific text search function (1).

Syntax:

MATCH (<col>, <col>, ...) AGAINST (<expr> [<search modifier>])

<col> = CompoundIdentifier
<expr> = String literal
§

Wildcard

§

QualifiedWildcard(ObjectName)

Qualified wildcard, e.g. alias.* or schema.table.*. (Same caveats apply to QualifiedWildcard as to Wildcard.)

§

OuterJoin(Box<Expr>)

Some dialects support an older syntax for outer joins where columns are marked with the (+) operator in the WHERE clause, for example:

SELECT t1.c1, t2.c2 FROM t1, t2 WHERE t1.c1 = t2.c2 (+)

which is equivalent to

SELECT t1.c1, t2.c2 FROM t1 LEFT OUTER JOIN t2 ON t1.c1 = t2.c2

See https://docs.snowflake.com/en/sql-reference/constructs/where#joins-in-the-where-clause.

Trait Implementations§

source§

impl Clone for Expr

source§

fn clone(&self) -> Expr

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Expr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Expr

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Expr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Expr> for FunctionArgExpr

source§

fn from(wildcard_expr: Expr) -> Self

Converts to this type from the input type.
source§

impl Hash for Expr

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Expr

source§

fn cmp(&self, other: &Expr) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Expr

source§

fn eq(&self, other: &Expr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Expr

source§

fn partial_cmp(&self, other: &Expr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Expr

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Visit for Expr

source§

fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break>

source§

impl VisitMut for Expr

source§

fn visit<V: VisitorMut>(&mut self, visitor: &mut V) -> ControlFlow<V::Break>

source§

impl Eq for Expr

source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,