agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Olivier Leprêtre <o.lepretre@gmail.com>
To: pgsql-sql@lists.postgresql.org
Subject: Window ?
Date: Wed, 13 Jun 2018 16:33:50 +0200
Message-ID: <5b212b57.1c69fb81.2e3b4.1d26@mx.google.com> (raw)

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

view thread (5+ messages)  latest in thread

Message-ID: <5b212b57.1c69fb81.2e3b4.1d26@mx.google.com>
Permalink:  ../5b212b57.1c69fb81.2e3b4.1d26@mx.google.com/
Also on:    postgresql.org/message-id/5b212b57.1c69fb81.2e3b4.1d26@mx.google.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: o.lepretre@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: Window ?
  In-Reply-To: <5b212b57.1c69fb81.2e3b4.1d26@mx.google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox