Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 46 variants Column { table: Option<String>, name: String, quote_style: QuoteStyle, table_quote_style: QuoteStyle, }, Number(String), StringLiteral(String), Boolean(bool), Null, BinaryOp { left: Box<Expr>, op: BinaryOperator, right: Box<Expr>, }, UnaryOp { op: UnaryOperator, expr: Box<Expr>, }, Function { name: String, args: Vec<Expr>, distinct: bool, filter: Option<Box<Expr>>, over: Option<WindowSpec>, }, Between { expr: Box<Expr>, low: Box<Expr>, high: Box<Expr>, negated: bool, }, InList { expr: Box<Expr>, list: Vec<Expr>, negated: bool, }, InSubquery { expr: Box<Expr>, subquery: Box<Statement>, negated: bool, }, AnyOp { expr: Box<Expr>, op: BinaryOperator, right: Box<Expr>, }, AllOp { expr: Box<Expr>, op: BinaryOperator, right: Box<Expr>, }, IsNull { expr: Box<Expr>, negated: bool, }, IsBool { expr: Box<Expr>, value: bool, negated: bool, }, Like { expr: Box<Expr>, pattern: Box<Expr>, negated: bool, escape: Option<Box<Expr>>, }, ILike { expr: Box<Expr>, pattern: Box<Expr>, negated: bool, escape: Option<Box<Expr>>, }, Case { operand: Option<Box<Expr>>, when_clauses: Vec<(Expr, Expr)>, else_clause: Option<Box<Expr>>, }, Nested(Box<Expr>), Wildcard, Subquery(Box<Statement>), Exists { subquery: Box<Statement>, negated: bool, }, Cast { expr: Box<Expr>, data_type: DataType, }, TryCast { expr: Box<Expr>, data_type: DataType, }, Extract { field: DateTimeField, expr: Box<Expr>, }, Interval { value: Box<Expr>, unit: Option<DateTimeField>, }, ArrayLiteral(Vec<Expr>), Tuple(Vec<Expr>), Coalesce(Vec<Expr>), If { condition: Box<Expr>, true_val: Box<Expr>, false_val: Option<Box<Expr>>, }, NullIf { expr: Box<Expr>, else: Box<Expr>, }, Collate { expr: Box<Expr>, collation: String, }, Parameter(String), TypeExpr(DataType), QualifiedWildcard { table: String, }, Star, Alias { expr: Box<Expr>, name: String, }, ArrayIndex { expr: Box<Expr>, index: Box<Expr>, }, JsonAccess { expr: Box<Expr>, path: Box<Expr>, as_text: bool, }, Lambda { params: Vec<String>, body: Box<Expr>, }, Default, Cube { exprs: Vec<Expr>, }, Rollup { exprs: Vec<Expr>, }, GroupingSets { sets: Vec<Expr>, }, TypedFunction { func: TypedFunction, filter: Option<Box<Expr>>, over: Option<WindowSpec>, }, Commented { expr: Box<Expr>, comments: Vec<String>, },
}
Expand description

An expression in SQL.

This enum is aligned with sqlglot’s Expression class hierarchy. Key additions over the basic implementation:

  • Subquery, Exists, Cast, Extract, Window functions
  • TypedString, Interval, Array/Struct constructors
  • Postgres-style casting (::)

Variants§

§

Column

A column reference, possibly qualified: [catalog.][schema.]table.column

Fields

§name: String
§quote_style: QuoteStyle

How the column name was quoted in the source SQL.

§table_quote_style: QuoteStyle

How the table qualifier was quoted, if present.

§

Number(String)

A numeric literal.

§

StringLiteral(String)

A string literal.

§

Boolean(bool)

A boolean literal.

§

Null

NULL literal.

§

BinaryOp

A binary operation: left op right

Fields

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

UnaryOp

A unary operation: op expr

Fields

§expr: Box<Expr>
§

Function

A function call: name(args...) with optional DISTINCT, ORDER BY, etc.

Fields

§name: String
§args: Vec<Expr>
§distinct: bool
§filter: Option<Box<Expr>>

FILTER (WHERE expr) clause on aggregate

§over: Option<WindowSpec>

OVER window specification for window functions

§

Between

expr BETWEEN low AND high

Fields

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

InList

expr IN (list...) or expr IN (subquery)

Fields

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

InSubquery

expr IN (SELECT ...)

Fields

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

AnyOp

expr op ANY(subexpr) — PostgreSQL array/subquery comparison

Fields

§expr: Box<Expr>
§right: Box<Expr>
§

AllOp

expr op ALL(subexpr) — PostgreSQL array/subquery comparison

Fields

§expr: Box<Expr>
§right: Box<Expr>
§

IsNull

expr IS [NOT] NULL

Fields

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

IsBool

expr IS [NOT] TRUE / expr IS [NOT] FALSE

Fields

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

Like

expr [NOT] LIKE pattern [ESCAPE escape_char]

Fields

§expr: Box<Expr>
§pattern: Box<Expr>
§negated: bool
§escape: Option<Box<Expr>>
§

ILike

expr [NOT] ILIKE pattern [ESCAPE escape_char] (case-insensitive LIKE)

Fields

§expr: Box<Expr>
§pattern: Box<Expr>
§negated: bool
§escape: Option<Box<Expr>>
§

Case

CASE [operand] WHEN ... THEN ... ELSE ... END

Fields

§operand: Option<Box<Expr>>
§when_clauses: Vec<(Expr, Expr)>
§else_clause: Option<Box<Expr>>
§

Nested(Box<Expr>)

A parenthesized sub-expression.

§

Wildcard

A wildcard * used in contexts like COUNT(*).

§

Subquery(Box<Statement>)

A scalar subquery: (SELECT ...)

§

Exists

EXISTS (SELECT ...)

Fields

§subquery: Box<Statement>
§negated: bool
§

Cast

CAST(expr AS type) or expr::type (PostgreSQL)

Fields

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

TryCast

TRY_CAST(expr AS type)

Fields

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

Extract

EXTRACT(field FROM expr)

Fields

§expr: Box<Expr>
§

Interval

INTERVAL 'value' unit

Fields

§value: Box<Expr>
§

ArrayLiteral(Vec<Expr>)

Array literal: ARRAY[1, 2, 3] or [1, 2, 3]

§

Tuple(Vec<Expr>)

Struct literal / row constructor: (1, 'a', true)

§

Coalesce(Vec<Expr>)

COALESCE(a, b, c)

§

If

IF(condition, true_val, false_val) (MySQL, BigQuery)

Fields

§condition: Box<Expr>
§true_val: Box<Expr>
§false_val: Option<Box<Expr>>
§

NullIf

NULLIF(a, b)

Fields

§expr: Box<Expr>
§else: Box<Expr>
§

Collate

expr COLLATE collation

Fields

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

Parameter(String)

Parameter / placeholder: $1, ?, :name

§

TypeExpr(DataType)

A type expression used in DDL contexts or CAST

§

QualifiedWildcard

table.* in expression context

Fields

§table: String
§

Star

Star expression *

§

Alias

Alias expression: expr AS name

Fields

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

ArrayIndex

Array access: expr[index]

Fields

§expr: Box<Expr>
§index: Box<Expr>
§

JsonAccess

JSON access: expr->key or expr->>key

Fields

§expr: Box<Expr>
§path: Box<Expr>
§as_text: bool

false = ->, true = ->>

§

Lambda

Lambda expression: x -> x + 1

Fields

§params: Vec<String>
§body: Box<Expr>
§

Default

DEFAULT keyword in INSERT/UPDATE contexts

§

Cube

CUBE(a, b, ...) in GROUP BY clause

Fields

§exprs: Vec<Expr>
§

Rollup

ROLLUP(a, b, ...) in GROUP BY clause

Fields

§exprs: Vec<Expr>
§

GroupingSets

GROUPING SETS ((a, b), (c), ...) in GROUP BY clause

Fields

§sets: Vec<Expr>
§

TypedFunction

A typed function expression with semantic awareness. Enables per-function, per-dialect code generation and transpilation.

Fields

§filter: Option<Box<Expr>>

FILTER (WHERE expr) clause on aggregate

§over: Option<WindowSpec>

OVER window specification for window functions

§

Commented

An expression with attached SQL comments. Wraps an inner expression so that comments survive transformations.

Fields

§expr: Box<Expr>
§comments: Vec<String>

Implementations§

Source§

impl Expr

Source

pub fn walk<F>(&self, visitor: &mut F)
where F: FnMut(&Expr) -> bool,

Recursively walk this expression tree, calling visitor on each node. If visitor returns false, children of that node are not visited.

Source

pub fn find<F>(&self, predicate: &F) -> Option<&Expr>
where F: Fn(&Expr) -> bool,

Find the first expression matching the predicate.

Source

pub fn find_all<F>(&self, predicate: &F) -> Vec<&Expr>
where F: Fn(&Expr) -> bool,

Find all expressions matching the predicate.

Source

pub fn transform<F>(self, func: &F) -> Expr
where F: Fn(Expr) -> Expr,

Transform this expression tree by applying a function to each node. The function can return a new expression to replace the current one.

Source

pub fn is_column(&self) -> bool

Check whether this expression is a column reference.

Source

pub fn is_literal(&self) -> bool

Check whether this expression is a literal value (number, string, bool, null).

Source

pub fn sql(&self) -> String

Get the SQL representation of this expression for display purposes. For full generation, use the Generator.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate 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 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 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 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 UnsafeUnpin 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

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

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