BUG #10972: string_agg function incorrectly concatenating varying delimiter - Mailing list pgsql-bugs

From jeff@goaldriven.com
Subject BUG #10972: string_agg function incorrectly concatenating varying delimiter
Date
Msg-id 20140716001632.2502.98836@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #10972: string_agg function incorrectly concatenating varying delimiter
Re: BUG #10972: string_agg function incorrectly concatenating varying delimiter
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      10972
Logged by:          Jeff Fischer
Email address:      jeff@goaldriven.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;

pgsql-bugs by date:

Previous
From: "Lars Ewald (web.de)"
Date:
Subject: Fwd: Re: Compile fails on AIX 6.1
Next
From: "Silambarasan Viswanathan"
Date:
Subject: Disable View rule