Re: Window ?

"David G. Johnston" <[email protected]>
Newsgroups gmane.comp.db.postgresql.sql
Message-ID <CAKFQuwY2E1GUmOoNDo-UdxiOSg4gErdpmzDYV5zRJ6JhBO60Uw@mail.gmail.com>
On Wed, Jun 13, 2018 at 7:33 AM, Olivier Leprêtre <[email protected]>
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.

https://www.postgresql.org/docs/10/static/tablefunc.html

David J.
​
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.