Window ?

From: Olivier Leprêtre <o(dot)lepretre(at)gmail(dot)com>
To: <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Window ?
Date: 2018-06-13 14:33:50
Message-ID: 5b212b57.1c69fb81.2e3b4.1d26@mx.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I have a road segment table with a few attributes for each. For each
segment, I have a road index and a segment index something like :

road seg colA

1 1 att1

1 2 att2

1 3 att3

1 4 att4

2 1 att5

2 2 att6

I want to convert records into lines,

1 att1 att2 att3 att4

2 att5 att6 ...

I was considering using window function, with a partition on road but the
problem is that segment count is different for each road, up to 30. So it's
seems a bit rough to write something like

select nth_value(colA,1), nth_value(colA,2), nth_value(colA,3),
nth_value(colA,4)...

Of course I can write a script with a loop to insert segments one road after
the other, but before going to this, I would appreciate a smarter idea !

Thanks

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gerardo Herzig 2018-06-13 14:51:11 Re: Window ?
Previous Message Alvin D?az 2018-05-07 01:56:07 Re: Access to table only through functions