Re: Window ? - Mailing list pgsql-sql

From David G. Johnston
Subject Re: Window ?
Date
Msg-id CAKFQuwY2E1GUmOoNDo-UdxiOSg4gErdpmzDYV5zRJ6JhBO60Uw@mail.gmail.com
Whole thread Raw
In response to Window ?  (Olivier Leprêtre <o.lepretre@gmail.com>)
Responses RE: Window ?  (Olivier Leprêtre <o.lepretre@gmail.com>)
List pgsql-sql
On Wed, Jun 13, 2018 at 7:33 AM, Olivier Leprêtre <o.lepretre@gmail.com> wrote:


I want to convert records into lines,

 

1        att1    att2    att3    att4

2        att5    att6    ...



​I would recommend either an actual array (array_agg function) or a structured string (string_agg function)

SELECT road, array_agg(colA ORDER BY seg)
FROM tbl
GROUP BY road;

Otherwise you will need a output 31 columns with unused columns holding null.  You can do that brute-force or you can leverage the tablefunc extension's crosstab function.


David J.

pgsql-sql by date:

Previous
From: Gerardo Herzig
Date:
Subject: Re: Window ?
Next
From: Olivier Leprêtre
Date:
Subject: RE: Window ?