pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: andrew.wheelwright@familysearch.org
Subject: BUG #16107: string_agg looses first item
Date: Mon, 11 Nov 2019 22:34:28 +0000
Message-ID: <16107-f46d9b66440d7f45@postgresql.org> (raw)

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.



view thread (2+ messages)  latest in thread

Message-ID: <16107-f46d9b66440d7f45@postgresql.org>
Permalink:  ../16107-f46d9b66440d7f45@postgresql.org/
Also on:    postgresql.org/message-id/16107-f46d9b66440d7f45@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, andrew.wheelwright@familysearch.org
  Subject: Re: BUG #16107: string_agg looses first item
  In-Reply-To: <16107-f46d9b66440d7f45@postgresql.org>
  References: <16107-f46d9b66440d7f45@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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