Re: string_agg delimiter having no effect with order by - Mailing list pgsql-bugs

From Robert Haas
Subject Re: string_agg delimiter having no effect with order by
Date
Msg-id AANLkTik+sKjNk-ocX86MXDK-U9xVmTdMtrC3aiTGxxkh@mail.gmail.com
Whole thread Raw
In response to Re: string_agg delimiter having no effect with order by  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: string_agg delimiter having no effect with order by  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Wed, Aug 4, 2010 at 11:29 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> Oh, yeah. =A0I guess you need this:
>
>> select thing, string_agg(stuff, ',' order by stuff) from agg_test
>> group by thing;
>
>> Rather than this:
>
>> select thing, string_agg(stuff order by stuff, ',') from agg_test
>> group by thing;
>
>> It's all kinds of not obvious to me what the second one is supposed to
>> mean, but I remember this was discussed before. =A0Perhaps we need a
>> <note> somewhere about multi-argument aggregates.
>
> Done:
>
> + =A0 =A0<para>
> + =A0 =A0 When dealing with multiple-argument aggregate functions, note t=
hat the
> + =A0 =A0 <literal>ORDER BY</> clause goes after all the aggregate argume=
nts.
> + =A0 =A0 For example, this:
> + <programlisting>
> + SELECT string_agg(a, ',' ORDER BY a) FROM table;
> + </programlisting>
> + =A0 =A0 not this:
> + <programlisting>
> + SELECT string_agg(a ORDER BY a, ',') FROM table; =A0-- not what you want
> + </programlisting>
> + =A0 =A0 The latter syntax will be accepted, but <literal>','</> will be
> + =A0 =A0 treated as a (useless) sort key.
> + =A0 =A0</para>

Oh, right, that's what it's supposed to mean.  Thanks for adding this.
 I suppose this confusion is only possible because string_agg has both
a one-argument and a two-argument form.

--=20
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: In 8.2, shutdown wrongly caused automatic restart
Next
From: Robert Haas
Date:
Subject: Re: BUG #5598: Compatibility modes