Expr

Enum Expr 

Source
pub enum Expr {
Show 19 variants Star, Named(String), Aliased { name: String, alias: String, }, Aggregate { col: String, func: AggregateFunc, distinct: bool, filter: Option<Vec<Condition>>, alias: Option<String>, }, Cast { expr: Box<Expr>, target_type: String, alias: Option<String>, }, Def { name: String, data_type: String, constraints: Vec<Constraint>, }, Mod { kind: ModKind, col: Box<Expr>, }, Window { name: String, func: String, params: Vec<Expr>, partition: Vec<String>, order: Vec<Cage>, frame: Option<WindowFrame>, }, Case { when_clauses: Vec<(Condition, Box<Expr>)>, else_value: Option<Box<Expr>>, alias: Option<String>, }, JsonAccess { column: String, path_segments: Vec<(String, bool)>, alias: Option<String>, }, FunctionCall { name: String, args: Vec<Expr>, alias: Option<String>, }, SpecialFunction { name: String, args: Vec<(Option<String>, Box<Expr>)>, alias: Option<String>, }, Binary { left: Box<Expr>, op: BinaryOp, right: Box<Expr>, alias: Option<String>, }, Literal(Value), ArrayConstructor { elements: Vec<Expr>, alias: Option<String>, }, RowConstructor { elements: Vec<Expr>, alias: Option<String>, }, Subscript { expr: Box<Expr>, index: Box<Expr>, alias: Option<String>, }, Collate { expr: Box<Expr>, collation: String, alias: Option<String>, }, FieldAccess { expr: Box<Expr>, field: String, alias: Option<String>, },
}

Variants§

§

Star

All columns (*)

§

Named(String)

§

Aliased

An aliased expression (expr AS alias)

Fields

§name: String
§alias: String
§

Aggregate

An aggregate function (COUNT(col)) with optional FILTER and DISTINCT

Fields

§distinct: bool
§filter: Option<Vec<Condition>>

PostgreSQL FILTER (WHERE …) clause for aggregates

§

Cast

Type cast expression (expr::type)

Fields

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

Def

Fields

§name: String
§data_type: String
§constraints: Vec<Constraint>
§

Mod

Fields

§kind: ModKind
§col: Box<Expr>
§

Window

Window Function Definition

Fields

§name: String
§func: String
§params: Vec<Expr>

Function arguments as expressions (e.g., for SUM(amount), use Expr::Named(“amount”))

§partition: Vec<String>
§order: Vec<Cage>
§

Case

CASE WHEN expression

Fields

§when_clauses: Vec<(Condition, Box<Expr>)>

WHEN condition THEN expr pairs (Expr allows functions, values, identifiers)

§else_value: Option<Box<Expr>>

ELSE expr (optional)

§alias: Option<String>

Optional alias

§

JsonAccess

JSON accessor (data->>‘key’ or data->‘key’ or chained data->‘a’->0->>‘b’)

Fields

§column: String

Base column name

§path_segments: Vec<(String, bool)>

JSON path segments: (key, as_text) as_text: true for ->> (extract as text), false for -> (extract as JSON) For chained access like x->‘a’->0->>‘b’, this is [(“a”, false), (“0”, false), (“b”, true)]

§alias: Option<String>

Optional alias

§

FunctionCall

Function call expression (COALESCE, NULLIF, etc.)

Fields

§name: String

Function name (coalesce, nullif, etc.)

§args: Vec<Expr>

Arguments to the function (now supports nested expressions)

§alias: Option<String>

Optional alias

§

SpecialFunction

Special SQL function with keyword arguments (SUBSTRING, EXTRACT, TRIM, etc.) e.g., SUBSTRING(expr FROM pos [FOR len]), EXTRACT(YEAR FROM date)

Fields

§name: String

Function name (SUBSTRING, EXTRACT, TRIM, etc.)

§args: Vec<(Option<String>, Box<Expr>)>

Arguments as (optional_keyword, expr) pairs e.g., [(None, col), (Some(“FROM”), 2), (Some(“FOR”), 5)]

§alias: Option<String>

Optional alias

§

Binary

Binary expression (left op right)

Fields

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

Literal(Value)

Literal value (string, number) for use in expressions e.g., ‘62’, 0, ‘active’

§

ArrayConstructor

Array constructor: ARRAY[expr1, expr2, …]

Fields

§elements: Vec<Expr>
§

RowConstructor

Row constructor: ROW(expr1, expr2, …) or (expr1, expr2, …)

Fields

§elements: Vec<Expr>
§

Subscript

Array/string subscript: arr[index]

Fields

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

Collate

Collation: expr COLLATE “collation_name”

Fields

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

FieldAccess

Field selection from composite: (row).field

Fields

§expr: Box<Expr>
§field: String

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

Source§

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

Formats the value using the given formatter. Read more
Source§

impl ExprExt for Expr

Source§

fn with_alias(self, alias: &str) -> Expr

Add an alias to this expression. Read more
Source§

fn or_default(self, default: impl Into<Expr>) -> Expr

COALESCE with a default value. Read more
Source§

fn json(self, key: &str) -> JsonBuilder

JSON text extraction (column->>‘key’). Read more
Source§

fn path(self, dotted_path: &str) -> JsonBuilder

JSON path extraction with dot notation. Read more
Source§

fn cast(self, target_type: &str) -> Expr

Cast to a type: CAST(expr AS type) Read more
Source§

fn upper(self) -> Expr

UPPER(expr)
Source§

fn lower(self) -> Expr

LOWER(expr)
Source§

fn trim(self) -> Expr

TRIM(expr)
Source§

fn length(self) -> Expr

LENGTH(expr)
Source§

fn abs(self) -> Expr

ABS(expr)
Source§

impl From<&String> for Expr

Source§

fn from(s: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Expr

Source§

fn from(s: &str) -> Self

Convert a string reference to a Named expression. Enables: .select(["id", "name"]) instead of .select([col("id"), col("name")])

Source§

impl From<AggregateBuilder> for Expr

Source§

fn from(builder: AggregateBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<BinaryBuilder> for Expr

Source§

fn from(builder: BinaryBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<CaseBuilder> for Expr

Source§

fn from(builder: CaseBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<CastBuilder> for Expr

Source§

fn from(builder: CastBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<ConcatBuilder> for Expr

Source§

fn from(builder: ConcatBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<FunctionBuilder> for Expr

Source§

fn from(builder: FunctionBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<JsonBuilder> for Expr

Source§

fn from(builder: JsonBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Expr

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
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 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> ToString for T
where T: Display + ?Sized,

Source§

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

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