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.