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 ] ]InList
[ NOT ] IN (val1, val2, ...)
InSubquery
[ NOT ] IN (SELECT ...)
Between
<expr> [ NOT ] BETWEEN <low> AND <high>
Like
LIKE
ILike
ILIKE (case-insensitive LIKE)
SimilarTo
<expr> [ NOT ] SIMILAR TO <pat> ESCAPE <esc_text>
BinaryOp
Binary operation e.g. 1 + 1 or foo > bar
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
Cast
CAST an expression to a different data type e.g. CAST(foo AS VARCHAR)
TryCast
TRY_CAST an expression to a different data type e.g. TRY_CAST(foo AS VARCHAR)
AtTimeZone
AT TIME ZONE converts timestamp without time zone to/from timestamp with time zone with
explicitly specified zone
Extract
EXTRACT(DateTimeField FROM <expr>)
Substring
SUBSTRING(<expr> [FROM <expr>] [FOR <expr>])
Position
POSITION(<expr> IN <expr>)
Overlay
OVERLAY(<expr> PLACING <expr> FROM <expr> [ FOR <expr> ])
Trim
TRIM([BOTH | LEADING | TRAILING] [<expr>] FROM <expr>)
Or
TRIM([BOTH | LEADING | TRAILING] [FROM] <expr> [, <expr>])
Collate
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
Parameter
Parameter Symbol e.g. $1, $1::int
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).
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
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']
ArrayRangeIndex
A slice expression arr[1:3]
LambdaFunction
Map
Trait Implementations§
impl Eq for Expr
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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