From: | Marti Raudsepp <marti(at)juffo(dot)org> |
---|---|
To: | Jeff Fischer <jeff(at)goaldriven(dot)com>, Dave <dave(at)goaldriven(dot)com> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #10972: string_agg function incorrectly concatenating varying delimiter |
Date: | 2014-07-23 08:17:32 |
Message-ID: | CABRT9RA=g1qs7rzy+J6bZG4Zt5QiBeKbfWUhKE78NH2MPbiWsw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Wed, Jul 16, 2014 at 3:16 AM, <jeff(at)goaldriven(dot)com> wrote:
> Running the query below will show how the delimiter for the current row is
> actually the subsequent rows delimiter. The sequence goes like this:
>
> TestBlah 1
> ITTest 2
> testfail 3
>
> Yet, the concatened output is this:
>
> "testblah 2 ITtest 3 testfail"
I think you're misunderstanding the point of the 2nd argument. It's
not there for just concatenating two arguments together, it's there to
be a delimiter between the strings being concatenated. Almost always
it should be a constant. For example if you want a result like
"TestBlah,ITTest,testfail", that would be much uglier to do without
the delimiter argument.
The behavior you want is available as simply:
string_agg(Field1 || ' ' || RowIndex::text, ' ')
Regards,
Marti
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2014-07-23 17:12:16 | syntax error WITH ORDINALITY |
Previous Message | shiguangsheng | 2014-07-23 07:24:20 | BUG #11025: could not access status of transaction 7 |