From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | andrew(dot)wheelwright(at)familysearch(dot)org |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #16107: string_agg looses first item |
Date: | 2019-11-11 22:47:39 |
Message-ID: | 27256.1573512459@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> I ran into a scenario where I found results getting dropped from string
> aggregation. Here's a basic example which reproduces the problem on three
> different servers running PostgreSQL 9.6.6, 10.6, and 11.5, respectively. I
> don't have an instance running version 12.
> with dataset as (
> select 'One' "Label", 1 "ID"
> union
> select 'Two' "Label", 2 "ID"
> union
> select 'Three' "Label", 3 "ID"
> )
> select
> string_agg(', ', "Label" order by "ID") "String Aggregated Labels",
> array_agg("Label" order by "ID") "Array Aggregated Labels"
> from
> dataset
> ;
> Which renders the following result:
> String Aggregated Labels: `, Two, Three, `
> Array Aggregated Labels: `{One,Two,Three}`
I think you've got the string_agg parameters backwards, it should be
regression=# with dataset as (
select 'One' "Label", 1 "ID"
union
select 'Two' "Label", 2 "ID"
union
select 'Three' "Label", 3 "ID"
)
select
string_agg("Label", ', ' order by "ID") "String Aggregated Labels",
array_agg("Label" order by "ID") "Array Aggregated Labels"
from
dataset
;
String Aggregated Labels | Array Aggregated Labels
--------------------------+-------------------------
One, Two, Three | {One,Two,Three}
(1 row)
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Kyotaro Horiguchi | 2019-11-12 07:22:01 | Re: [BUG FIX] Uninitialized var fargtypes used. |
Previous Message | PG Bug reporting form | 2019-11-11 22:34:28 | BUG #16107: string_agg looses first item |