Enum sql_ast::ast::Expr

source ·
pub enum Expr {
Show 21 variants Identifier(Ident), Wildcard, QualifiedWildcard(Vec<Ident>), CompoundIdentifier(Vec<Ident>), IsNull(Box<Expr>), IsNotNull(Box<Expr>), InList { expr: Box<Expr>, list: Vec<Expr>, negated: bool, }, ValueList(Vec<Expr>), InSubquery { expr: Box<Expr>, subquery: Box<Query>, 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, }, Extract { field: DateTimeField, expr: Box<Expr>, }, Collate { expr: Box<Expr>, collation: ObjectName, }, Nested(Box<Expr>), Value(Value), Function(Function), Case { operand: Option<Box<Expr>>, conditions: Vec<Expr>, results: Vec<Expr>, else_result: Option<Box<Expr>>, }, Exists(Box<Query>), Subquery(Box<Query>),
}
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

§

Wildcard

Unqualified wildcard (*). SQL allows this in limited contexts, such as:

  • right after SELECT (which is represented as a SelectItem::Wildcard instead)
  • or as part of an aggregate function, e.g. COUNT(*),

…but we currently also accept it in contexts where it doesn’t make sense, such as * + *

§

QualifiedWildcard(Vec<Ident>)

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

§

CompoundIdentifier(Vec<Ident>)

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

§

IsNull(Box<Expr>)

IS NULL expression

§

IsNotNull(Box<Expr>)

IS NOT NULL expression

§

InList

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

Fields

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

ValueList(Vec<Expr>)

§

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

BinaryOp

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

Fields

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

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

Fields

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

Extract

Fields

§expr: 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

§

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

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

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