| From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
|---|---|
| To: | Olivier Leprêtre <o(dot)lepretre(at)gmail(dot)com> |
| Cc: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Window ? |
| Date: | 2018-06-13 14:54:45 |
| Message-ID: | CAKFQuwY2E1GUmOoNDo-UdxiOSg4gErdpmzDYV5zRJ6JhBO60Uw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Wed, Jun 13, 2018 at 7:33 AM, Olivier Leprêtre <o(dot)lepretre(at)gmail(dot)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.
https://www.postgresql.org/docs/10/static/tablefunc.html
David J.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Olivier Leprêtre | 2018-06-13 15:14:45 | RE: Window ? |
| Previous Message | Gerardo Herzig | 2018-06-13 14:51:11 | Re: Window ? |