risingwave_sqlparser::ast

Enum Expr

source
pub enum Expr {
Show 51 variants Identifier(Ident), CompoundIdentifier(Vec<Ident>), FieldIdentifier(Box<Expr>, Vec<Ident>), IsNull(Box<Expr>), IsNotNull(Box<Expr>), IsTrue(Box<Expr>), IsNotTrue(Box<Expr>), IsFalse(Box<Expr>), IsNotFalse(Box<Expr>), IsUnknown(Box<Expr>), IsNotUnknown(Box<Expr>), IsDistinctFrom(Box<Expr>, Box<Expr>), IsNotDistinctFrom(Box<Expr>, Box<Expr>), IsJson { expr: Box<Expr>, negated: bool, item_type: JsonPredicateType, unique_keys: bool, }, InList { expr: Box<Expr>, list: Vec<Expr>, negated: bool, }, InSubquery { expr: Box<Expr>, subquery: Box<Query>, negated: bool, }, Between { expr: Box<Expr>, negated: bool, low: Box<Expr>, high: Box<Expr>, }, Like { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<EscapeChar>, }, ILike { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<EscapeChar>, }, SimilarTo { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<EscapeChar>, }, BinaryOp { left: Box<Expr>, op: BinaryOperator, right: Box<Expr>, }, SomeOp(Box<Expr>), AllOp(Box<Expr>), UnaryOp { op: UnaryOperator, expr: Box<Expr>, }, Cast { expr: Box<Expr>, data_type: DataType, }, TryCast { expr: Box<Expr>, data_type: DataType, }, AtTimeZone { timestamp: Box<Expr>, time_zone: Box<Expr>, }, Extract { field: String, expr: Box<Expr>, }, Substring { expr: Box<Expr>, substring_from: Option<Box<Expr>>, substring_for: Option<Box<Expr>>, }, Position { substring: Box<Expr>, string: Box<Expr>, }, Overlay { expr: Box<Expr>, new_substring: Box<Expr>, start: Box<Expr>, count: Option<Box<Expr>>, }, Trim { expr: Box<Expr>, trim_where: Option<TrimWhereField>, trim_what: Option<Box<Expr>>, }, Collate { expr: Box<Expr>, collation: ObjectName, }, Nested(Box<Expr>), Value(Value), Parameter { index: u64, }, TypedString { data_type: DataType, value: String, }, Function(Function), Case { operand: Option<Box<Expr>>, conditions: Vec<Expr>, results: Vec<Expr>, else_result: Option<Box<Expr>>, }, Exists(Box<Query>), Subquery(Box<Query>), GroupingSets(Vec<Vec<Expr>>), Cube(Vec<Vec<Expr>>), Rollup(Vec<Vec<Expr>>), Row(Vec<Expr>), Array(Array), ArraySubquery(Box<Query>), Index { obj: Box<Expr>, index: Box<Expr>, }, ArrayRangeIndex { obj: Box<Expr>, start: Option<Box<Expr>>, end: Option<Box<Expr>>, }, LambdaFunction { args: Vec<Ident>, body: Box<Expr>, }, Map { entries: Vec<(Expr, 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

§

FieldIdentifier(Box<Expr>, Vec<Ident>)

Struct-field identifier. Expr is an arbitrary expression, returning either a table or a column. Idents are consecutive field accesses. e.g. (table.v1).v2 or (table).v1.v2

It must contain parentheses to be distinguished from a Expr::CompoundIdentifier. See also https://www.postgresql.org/docs/current/rowtypes.html#ROWTYPES-ACCESSING

The left parentheses must be put at the beginning of the expression. The first parenthesized part is the expr part, and the rest are flattened into idents. e.g., ((v1).v2.v3).v4 is equivalent to (v1).v2.v3.v4.

§

IsNull(Box<Expr>)

IS NULL operator

§

IsNotNull(Box<Expr>)

IS NOT NULL operator

§

IsTrue(Box<Expr>)

IS TRUE operator

§

IsNotTrue(Box<Expr>)

IS NOT TRUE operator

§

IsFalse(Box<Expr>)

IS FALSE operator

§

IsNotFalse(Box<Expr>)

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

§

IsJson

IS [ NOT ] JSON [ VALUE | ARRAY | OBJECT | SCALAR ]
[ { WITH | WITHOUT } UNIQUE [ KEYS ] ]

Fields

§expr: Box<Expr>
§negated: bool
§unique_keys: bool
§

InList

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

Fields

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

InSubquery

[ NOT ] IN (SELECT ...)

Fields

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

Between

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

Fields

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

Like

LIKE

Fields

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

ILike

ILIKE (case-insensitive LIKE)

Fields

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

SimilarTo

<expr> [ NOT ] SIMILAR TO <pat> ESCAPE <esc_text>

Fields

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

BinaryOp

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

Fields

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

SomeOp(Box<Expr>)

Some operation e.g. foo > Some(bar), It will be wrapped in the right side of BinaryExpr

§

AllOp(Box<Expr>)

ALL operation e.g. foo > ALL(bar), It will be wrapped in the right side of BinaryExpr

§

UnaryOp

Unary operation e.g. NOT foo

Fields

§expr: Box<Expr>
§

Cast

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

Fields

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

TryCast

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

Fields

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

AtTimeZone

AT TIME ZONE converts timestamp without time zone to/from timestamp with time zone with explicitly specified zone

Fields

§timestamp: Box<Expr>
§time_zone: Box<Expr>
§

Extract

EXTRACT(DateTimeField FROM <expr>)

Fields

§field: String
§expr: Box<Expr>
§

Substring

SUBSTRING(<expr> [FROM <expr>] [FOR <expr>])

Fields

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

Position

POSITION(<expr> IN <expr>)

Fields

§substring: Box<Expr>
§string: Box<Expr>
§

Overlay

OVERLAY(<expr> PLACING <expr> FROM <expr> [ FOR <expr> ])

Fields

§expr: Box<Expr>
§new_substring: Box<Expr>
§start: Box<Expr>
§count: Option<Box<Expr>>
§

Trim

TRIM([BOTH | LEADING | TRAILING] [<expr>] FROM <expr>)
Or
TRIM([BOTH | LEADING | TRAILING] [FROM] <expr> [, <expr>])

Fields

§expr: Box<Expr>
§trim_what: Option<Box<Expr>>
§

Collate

expr COLLATE collation

Fields

§expr: Box<Expr>
§collation: ObjectName
§

Nested(Box<Expr>)

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

§

Value(Value)

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

§

Parameter

Parameter Symbol e.g. $1, $1::int

Fields

§index: u64
§

TypedString

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

Fields

§data_type: DataType
§value: String
§

Function(Function)

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

§

Case

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

Fields

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

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

§

GroupingSets(Vec<Vec<Expr>>)

The GROUPING SETS expr.

§

Cube(Vec<Vec<Expr>>)

The CUBE expr.

§

Rollup(Vec<Vec<Expr>>)

The ROLLUP expr.

§

Row(Vec<Expr>)

The ROW expr. The ROW keyword can be omitted,

§

Array(Array)

An array constructor ARRAY[[2,3,4],[5,6,7]]

§

ArraySubquery(Box<Query>)

An array constructing subquery ARRAY(SELECT 2 UNION SELECT 3)

§

Index

A subscript expression arr[1] or map['a']

Fields

§obj: Box<Expr>
§index: Box<Expr>
§

ArrayRangeIndex

A slice expression arr[1:3]

Fields

§obj: Box<Expr>
§start: Option<Box<Expr>>
§

LambdaFunction

Fields

§args: Vec<Ident>
§body: Box<Expr>
§

Map

Fields

§entries: Vec<(Expr, Expr)>

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 Display for Expr

source§

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

Formats the value using the given formatter. Read more
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 PartialEq for Expr

source§

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

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

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

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

impl Eq for Expr

source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

source§

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

source§

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

source§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more