Skip to main content

Combines

Struct Combines 

Source
pub struct Combines {
    pub queries: Vec<Combine>,
    pub order_by: OrderBy,
    pub limit: Limit,
    pub offset: Offset,
    pub fetch: Fetch,
}
Expand description

Every set operation chained onto one statement, and the ORDER BY / LIMIT / OFFSET / FETCH that belong to the combination rather than to any one operand.

That second half is the part worth getting right. PostgreSQL 17, https://www.postgresql.org/docs/17/sql-select.html:

select_statement UNION [ALL] select_statement

ORDER BY and LIMIT … can be attached to a subexpression if it is enclosed in parentheses. Without parentheses, these clauses will be taken to apply to the result of the UNION, not to its right-hand input expression.

So a statement with set operations has two sets of trailing clauses that render in different places, and the difference is invisible in the SQL text except through the parentheses:

(SELECT … LIMIT 1) UNION ALL (SELECT …) ORDER BY 1 LIMIT 5
 ^ the leading query's own LIMIT           ^ the combination's

The leading query’s clauses stay where the query writes them, and are wrapped; the combination’s live here and are written after the last operand. parenthesises_leading_query is the condition for the wrapping.

No keyword of its own: every Combine starts with its operator.

Fields§

§queries: Vec<Combine>

The operations, applied left to right.

§order_by: OrderBy

ORDER BY over the result of the combination.

§limit: Limit

LIMIT over the result of the combination.

§offset: Offset

OFFSET over the result of the combination.

§fetch: Fetch

FETCH over the result of the combination.

Implementations§

Source§

impl Combines

Source

pub fn append_combine(&mut self, combine: Combine)

Append one set operation.

Source

pub fn is_empty(&self) -> bool

Whether anything at all is combined.

Source

pub fn parenthesises_leading_query( &self, leading_has_tail_clauses: bool, ) -> bool

Whether the statement in front of these operations has to be parenthesised.

It does exactly when it carries a trailing clause of its own — ORDER BY, LIMIT, OFFSET, FETCH or a locking clause — and something is combined onto it, because without the parentheses that clause would silently move to the whole combination. leading_has_tail_clauses is what only the query type can know.

With nothing combined the parentheses would be legal but pointless, so they are left out; that is also why an all-default Combines changes nothing about how a statement renders.

Trait Implementations§

Source§

impl Clone for Combines

Source§

fn clone(&self) -> Combines

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Combines

Source§

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

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

impl Default for Combines

Source§

fn default() -> Combines

Returns the “default value” for a type. Read more
Source§

impl Expression for Combines

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Append this fragment to w. Read more
Source§

impl HasCombines for Combines

Source§

fn combines_mut(&mut self) -> &mut Combines

The set operations to modify.

Auto Trait Implementations§

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.