Expr in sqlparser::ast - Rust

pub enum Expr {
Show 63 variants Identifier(Ident), CompoundIdentifier(Vec<Ident>), CompoundFieldAccess { root: Box<Expr>, access_chain: Vec<AccessExpr>, }, JsonAccess { value: Box<Expr>, path: JsonPath, }, 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>), IsNormalized { expr: Box<Expr>, form: Option<NormalizationForm>, negated: bool, }, 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, any: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<Value>, }, ILike { negated: bool, any: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<Value>, }, SimilarTo { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, escape_char: Option<Value>, }, RLike { negated: bool, expr: Box<Expr>, pattern: Box<Expr>, regexp: bool, }, AnyOp { left: Box<Expr>, compare_op: BinaryOperator, right: Box<Expr>, is_some: bool, }, AllOp { left: Box<Expr>, compare_op: BinaryOperator, right: Box<Expr>, }, UnaryOp { op: UnaryOperator, expr: Box<Expr>, }, Convert { is_try: bool, expr: Box<Expr>, data_type: Option<DataType>, charset: Option<ObjectName>, target_before_value: bool, styles: Vec<Expr>, }, Cast { kind: CastKind, expr: Box<Expr>, data_type: DataType, array: bool, format: Option<CastFormat>, }, AtTimeZone { timestamp: Box<Expr>, time_zone: Box<Expr>, }, Extract { field: DateTimeField, syntax: ExtractSyntax, expr: Box<Expr>, }, Ceil { expr: Box<Expr>, field: CeilFloorKind, }, Floor { expr: Box<Expr>, field: CeilFloorKind, }, Position { expr: Box<Expr>, in: Box<Expr>, }, Substring { expr: Box<Expr>, substring_from: Option<Box<Expr>>, substring_for: Option<Box<Expr>>, special: bool, shorthand: 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(ValueWithSpan), Prefixed { prefix: Ident, value: Box<Expr>, }, TypedString(TypedString), Function(Function), Case { case_token: AttachedToken, end_token: AttachedToken, operand: Option<Box<Expr>>, conditions: Vec<CaseWhen>, else_result: Option<Box<Expr>>, }, Exists { subquery: Box<Query>, negated: bool, }, Subquery(Box<Query>), 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, }, Dictionary(Vec<DictionaryField>), Map(Map), Array(Array), Interval(Interval), MatchAgainst { columns: Vec<ObjectName>, match_value: Value, opt_search_modifier: Option<SearchModifier>, }, Wildcard(AttachedToken), QualifiedWildcard(ObjectName, AttachedToken), OuterJoin(Box<Expr>), Prior(Box<Expr>), Lambda(LambdaFunction), MemberOf(MemberOf),
}
Expand description

An SQL expression of any type.

§Semantics / Type Checking

The parser does not distinguish between expressions of different types (e.g. boolean vs string). The caller is responsible for detecting and validating types as necessary (for example WHERE 1 vs SELECT 1=1) See the README.md for more details.

§Equality and Hashing Does not Include Source Locations

The Expr type implements PartialEq and Eq based on the semantic value of the expression (not bitwise comparison). This means that Expr instances that are semantically equivalent but have different spans (locations in the source tree) will compare as equal.

§

Identifier e.g. table name or column name

§

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

§

Multi-part expression access.

This structure represents an access chain in structured / nested types such as maps, arrays, and lists:

  • Array
    • A 1-dim array a[1] will be represented like: CompoundFieldAccess(Ident('a'), vec![Subscript(1)]
    • A 2-dim array a[1][2] will be represented like: CompoundFieldAccess(Ident('a'), vec![Subscript(1), Subscript(2)]
  • Map or Struct (Bracket-style)
    • A map a['field1'] will be represented like: CompoundFieldAccess(Ident('a'), vec![Subscript('field')]
    • A 2-dim map a['field1']['field2'] will be represented like: CompoundFieldAccess(Ident('a'), vec![Subscript('field1'), Subscript('field2')]
  • Struct (Dot-style) (only effect when the chain contains both subscript and expr)
    • A struct access a[field1].field2 will be represented like: CompoundFieldAccess(Ident('a'), vec![Subscript('field1'), Ident('field2')]
  • If a struct access likes a.field1.field2, it will be represented by CompoundIdentifier([a, field1, field2])

Fields

The base expression being accessed.

Sequence of access operations (subscript or identifier accesses).

§

Fields

The path to the data to extract.

§

IS FALSE operator

§

IS NOT FALSE operator

§

IS TRUE operator

§

IS NOT TRUE operator

§

IS NULL operator

§

IS NOT NULL operator

§

IS UNKNOWN operator

§

IS NOT UNKNOWN operator

§

IS DISTINCT FROM operator

§

IS NOT DISTINCT FROM operator

§

<expr> IS [ NOT ] [ form ] NORMALIZED

Fields

Optional normalization form (e.g., NFC, NFD).

true when NOT is present.

§

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

Fields

Left-hand expression to test for membership.

Literal list of expressions to check against.

true when the NOT modifier is present.

§

[ NOT ] IN (SELECT ...)

Fields

Left-hand expression to test for membership.

The subquery providing the candidate values.

true when the NOT modifier is present.

§

[ NOT ] IN UNNEST(array_expression)

Fields

Left-hand expression to test for membership.

Array expression being unnested.

true when the NOT modifier is present.

§

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

Fields

Expression being compared.

true when the NOT modifier is present.

§

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

Fields

Operator between operands.

§

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

Fields

true when NOT is present.

Optional escape character.

§

ILIKE (case-insensitive LIKE)

Fields

true when NOT is present.

Optional escape character.

§

SIMILAR TO regex

Fields

true when NOT is present.

Optional escape character.

§

MySQL: RLIKE regex or REGEXP regex

Fields

true when NOT is present.

true for REGEXP, false for RLIKE (no difference in semantics)

§

Fields

Right-hand subquery expression.

§

Fields

Right-hand subquery expression.

§

Unary operation e.g. NOT foo

Fields

The unary operator (e.g., NOT, -).

§

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

Fields

The expression to convert.

The target data type, if provided.

Optional target character encoding (e.g., utf8mb4).

true when target precedes the value (MSSQL syntax).

How to translate the expression.

§

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

Fields

The cast kind (e.g., CAST, TRY_CAST).

MySQL allows CAST(… AS type ARRAY) in functional index definitions for InnoDB multi-valued indices. It’s not really a datatype, and is only allowed in CAST in key specifications, so it’s a flag here.

Optional CAST(string_expression AS type FORMAT format_string_expression) as used by BigQuery

§

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

Fields

Timestamp expression to shift.

Time zone expression to apply.

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

Syntax:

EXTRACT(DateTimeField FROM <expr>) | EXTRACT(DateTimeField, <expr>)
§
CEIL(<expr> [TO DateTimeField])
CEIL( <input_expr> [, <scale_expr> ] )

Fields

The CEIL/FLOOR kind (datetime field or scale).

§
FLOOR(<expr> [TO DateTimeField])
FLOOR( <input_expr> [, <scale_expr> ] )

Fields

The CEIL/FLOOR kind (datetime field or scale).

§
POSITION(<expr> in <expr>)

Fields

Expression to search for.

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

or

SUBSTRING(<expr>, <expr>, <expr>)

Fields

Optional FROM expression.

false if the expression is represented using the SUBSTRING(expr [FROM start] [FOR len]) syntax true if the expression is represented using the SUBSTRING(expr, start, len) syntax This flag is used for formatting.

§shorthand: bool

true if the expression is represented using the SUBSTR shorthand This flag is used for formatting.

§
TRIM([BOTH | LEADING | TRAILING] [<expr> FROM] <expr>)
TRIM(<expr>)
TRIM(<expr>, [, characters]) -- only Snowflake or Bigquery

Fields

The expression to trim from.

Which side to trim: BOTH, LEADING, or TRAILING.

Optional expression specifying what to trim from the value.

Optional list of characters to trim (dialect-specific).

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

Fields

The target expression being overlayed.

The expression to place into the target.

The FROM position expression indicating where to start overlay.

Optional FOR length expression limiting the overlay span.

§

expr COLLATE collation

Fields

The expression being collated.

The collation name to apply to the expression.

§

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

§

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

§

Fields

The prefix identifier (introducer or projection prefix).

The value expression being prefixed. Hint: you can unwrap the string value using value.into_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).

§

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

§

Fields

The attached CASE token (keeps original spacing/comments).

The attached END token (keeps original spacing/comments).

§operand: Option<Box<Expr>>

Optional operand expression after CASE (for simple CASE).

The WHEN ... THEN conditions and results.

Optional ELSE result expression.

§

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

Fields

The subquery checked by EXISTS.

Whether the EXISTS is negated (NOT EXISTS).

§

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

§

The GROUPING SETS expr.

§

The CUBE expr.

§

The ROLLUP expr.

§

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

§

Struct literal expression Syntax:

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

[BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type)
[Databricks](https://docs.databricks.com/en/sql/language-manual/functions/struct.html)

Fields

Struct field definitions.

§

BigQuery specific: An named expression in a typeless struct 1

Syntax

Fields

The expression being named.

The assigned identifier name for the expression.

§

DuckDB specific Struct literal expression 1

Syntax:

syntax: {'field_name': expr1[, ... ]}
§

DuckDB specific Map literal expression 1

Syntax:

syntax: Map {key1: value1[, ... ]}
§

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

§

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

§

MySQL specific text search function (1).

Syntax:

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

<col> = CompoundIdentifier
<expr> = String literal

Fields

§

An unqualified * wildcard token (e.g. *).

§

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

§
§

A reference to the prior level in a CONNECT BY clause.

§
§

Checks membership of a value in a JSON array

§
§
§
§
§
§