BUG #10972: string_agg function incorrectly concatenating varying delimiter

From: jeff(at)goaldriven(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #10972: string_agg function incorrectly concatenating varying delimiter
Date: 2014-07-16 00:16:32
Message-ID: 20140716001632.2502.98836@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 10972
Logged by: Jeff Fischer
Email address: jeff(at)goaldriven(dot)com
PostgreSQL version: 9.3.1
Operating system: CentOS
Description:

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"

You can see that the delimiter for the current row is actually getting the
subsequent rows delimiter. It's as though the string concat moves to the
next row prior to concatenting the delimiter, which is likely the cause of
this bug.

SELECT
string_agg(
Field1,
' ' || RowIndex::text || ' '
ORDER BY RowIndex) as VeryLongConcatenatedResultsFieldName
FROM (
SELECT
'testblah' as Field1,
1 as RowIndex
UNION
SELECT
'ITtest' as Field1,
2 as RowIndex
UNION
SELECT
'testfail' as Field1,
3 as RowIndex
) t;

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2014-07-16 01:51:39 Re: BUG #10794: psql sometimes ignores .psqlrc
Previous Message Marko Tiikkaja 2014-07-15 22:01:21 Re: BUG #10794: psql sometimes ignores .psqlrc