Skip to main content

StringAgg

Struct StringAgg 

Source
pub struct StringAgg;
Expand description

string_agg(column, ", ") — a group’s values run together, separated. NULL over zero rows, and over a group whose every value is NULL.

The separator binds like any other value under Postgres and SQLite, which take it as an ordinary argument. MySQL’s grammar takes a literal after SEPARATOR and rejects a parameter, so there alone it is written into the SQL and escaped — which is why it is a &'static str at all, and why a MySQL session running NO_BACKSLASH_ESCAPES renders a separator containing a backslash as more backslashes than were asked for. &'static str is a nudge and not a guarantee, since Box::leak reaches it; the guarantee is that the two dialects this crate executes never write it out at all.

Two string_aggs over one column key alike, since the separator is not part of the key — give one a label!{} name to read both back.

Known limitation: no ORDER BY inside the call (string_agg(x, ',' ORDER BY x)) and no DISTINCT. Ordering inside an aggregate reached SQLite only in 3.44, past the 3.39 this crate targets, and MySQL spells it before the separator rather than after the argument — three spellings of a clause two of the dialects would have to be told to skip. Reach for sql!{} where the order matters.

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> 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<S> Superset<Nil, Nil> for S

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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> WrapNullable<NotNull> for T