Expr

Enum Expr 

Source
pub enum Expr {
Show 17 variants Column(Name), Literal(Cell), And(Vec<Expr>), Or(Vec<Expr>), Not(Box<Expr>), Cmp(Box<Expr>, CmpOp, Box<Expr>), Is { value: Box<Expr>, to: Option<bool>, negated: bool, }, In { value: Box<Expr>, list: Vec<Expr>, negated: bool, }, Match { value: Box<Expr>, pattern: Box<Expr>, negated: bool, insensitive: bool, }, Case { operand: Option<Box<Expr>>, arms: Vec<(Expr, Expr)>, otherwise: Option<Box<Expr>>, }, Call { name: String, args: Vec<Expr>, }, Cast { value: Box<Expr>, ty: String, }, Concat(Box<Expr>, Box<Expr>), Subquery { id: usize, select: Box<Select>, }, Array { id: usize, select: Box<Select>, }, Any(Box<Expr>), Subscript(Box<Expr>, Box<Expr>),
}
Expand description

A scalar expression, evaluated over one row.

Every variant here is something a catalogue query writes. What is not here is arithmetic, because nothing asks for it: a read model computes its numbers in the program.

Variants§

§

Column(Name)

§

Literal(Cell)

A literal, or null — which is why this is a Cell rather than a Datum.

§

And(Vec<Expr>)

§

Or(Vec<Expr>)

§

Not(Box<Expr>)

§

Cmp(Box<Expr>, CmpOp, Box<Expr>)

a = b, and the other five comparisons. Three-valued: a comparison against NULL is unknown, and unknown is not true.

§

Is

a is null / a is not null, and a is true / a is not false.

Fields

§value: Box<Expr>
§to: Option<bool>

None for is null.

§negated: bool
§

In

c in ('r', 'v') — the form psql narrows relkind with.

Fields

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

Match

~, !~, ~*, !~* — a POSIX regular expression match, run by a simulation over a set of states rather than by backtracking, because the pattern arrives from a client.

Fields

§value: Box<Expr>
§pattern: Box<Expr>
§negated: bool
§insensitive: bool
§

Case

case … when … then … else … end, in both SQL’s forms.

Lazy, as SQL specifies: the arms after the one that matched are not evaluated. That is load-bearing here rather than an optimisation — psql writes case when c.reloftype = 0 then '' else c.reloftype::regtype::text end, and the branch this catalogue cannot compute is the branch no row reaches.

Fields

§operand: Option<Box<Expr>>
§arms: Vec<(Expr, Expr)>
§otherwise: Option<Box<Expr>>
§

Call

A function call. crate::pg::call is what answers one, and a name it does not know is refused by name rather than answered NULL.

Fields

§name: String
§args: Vec<Expr>
§

Cast

x::text. A cast to a type this has is the value; to anything else it is refused by name, which is why the case above has to be lazy.

Fields

§value: Box<Expr>
§

Concat(Box<Expr>, Box<Expr>)

a || b, string concatenation.

§

Subquery

A scalar subquery — (select … from …).

The id distinguishes two subqueries in one statement, so the answer to each can be computed once rather than once per row: see Eval::subquery for why it is the same for every row.

Fields

§select: Box<Select>
§

Array

array(select …) and any(x): parsed, and refused by name if a row ever asks. Both appear in psql’s catalogue queries inside branches that no row reaches, and a query refused at parse time for a branch it never takes is a \d that does not work.

Fields

§select: Box<Select>
§

Any(Box<Expr>)

§

Subscript(Box<Expr>, Box<Expr>)

x[i], an array subscript. Parsed for Expr::Array’s reason and refused for the same one.

Implementations§

Source§

impl Expr

Source

pub fn names(&self, out: &mut Vec<Name>)

Every column this expression names, including those in a subquery it carries.

crate::query uses it to decide which table a where term narrows, so a term that names a column inside a subquery counts as naming it: pushing such a term into one table’s scan would evaluate the subquery against the wrong rows.

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

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