pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #16107: string_agg looses first item
2+ messages / 2 participants
[nested] [flat]
* BUG #16107: string_agg looses first item
@ 2019-11-11 22:34 PG Bug reporting form <noreply@postgresql.org>
2019-11-11 22:47 ` Re: BUG #16107: string_agg looses first item Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2019-11-11 22:34 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: andrew.wheelwright@familysearch.org
The following bug has been logged on the website:
Bug reference: 16107
Logged by: Andrew Wheelwright
Email address: andrew.wheelwright@familysearch.org
PostgreSQL version: 11.5
Operating system: Linux
Description:
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}`
The value "One" is missing from the string aggregate result and there is a
dangling separator on both ends of the string.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #16107: string_agg looses first item
2019-11-11 22:34 BUG #16107: string_agg looses first item PG Bug reporting form <noreply@postgresql.org>
@ 2019-11-11 22:47 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2019-11-11 22:47 UTC (permalink / raw)
To: andrew.wheelwright@familysearch.org; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-11-11 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 22:34 BUG #16107: string_agg looses first item PG Bug reporting form <noreply@postgresql.org>
2019-11-11 22:47 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox