From: | Olivier Leprêtre <o(dot)lepretre(at)gmail(dot)com> |
---|---|
To: | "'pgsql-sql'" <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | RE: Window ? |
Date: | 2018-06-13 15:14:45 |
Message-ID: | 5b2134ec.1c69fb81.7dd50.7e8f@mx.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Thanks David, Gerardo,
I had a look to crosstab functions but wasn't able to make them work, documentation is not precise enough to me, I would appreciate if someone has a working sample. Based on your suggestion, I will try again anyway. The main difficulty is that I have not only one column but half a dozen taht I would like to appear
road 1 colA colB colC colD colE ColF colA colB colC colD colE ColF colA colB colC colD colE ColF ...
road 2 colA colB...
for each road.
Olivier
De : David G. Johnston [mailto:david(dot)g(dot)johnston(at)gmail(dot)com]
Envoyé : mercredi 13 juin 2018 16:55
À : Olivier Leprêtre
Cc : pgsql-sql
Objet : Re: Window ?
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.
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
From | Date | Subject | |
---|---|---|---|
Next Message | Gerardo Herzig | 2018-06-13 15:22:14 | Re: Window ? |
Previous Message | David G. Johnston | 2018-06-13 14:54:45 | Re: Window ? |