[postgis-users] Create mutliple rows from a field

Olivier Leprêtre o.lepretre at gmail.com
Thu May 18 10:39:13 PDT 2017


Thanks very much Nathan and Mickael for those quick and good answers !

Olivier
-----Message d'origine-----
De : postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] De la part de Nathan Wagner
Envoyé : jeudi 18 mai 2017 19:21
À : PostGIS Users Discussion
Objet : Re: [postgis-users] Create mutliple rows from a field

On Thu, May 18, 2017 at 07:05:39PM +0200, Olivier Lepr?tre wrote:

[ excess newlines snipped]

> I have a table with 2 columns : id, x (x is an int from 0 to n)

> Is it possible to create a query that will return x ranked rows for 
> each id ?

> with

> id       x
> A        2
> B        3
> C        1
> D       4

> will return

> A        1
> A        2
> B        1
> B        2
> B        3
> C        1
> D       1
> D       2
> D       3
> D       4

create table foo (id text, x integer);
insert into foo
values ('A',2),('B',3),('C',1),('D',4)
;
select id, generate_series(1, x) as r from foo;

--
nw
_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users


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



More information about the postgis-users mailing list