Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] lié un generate_series et un autre select

From: Cédric Villemain <cedric(dot)villemain(dot)debian(at)gmail(dot)com>
To: Bruno Friedmann <bruno(at)ioda-net(dot)ch>
Cc: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] lié un generate_series et un autre select
Date: 2010-11-01 11:59:47
Message-ID: AANLkTi=ZdTo+V7d1bHR16HzjNbekGbHmtzU9g6Dd9GfC@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

Le 1 novembre 2010 12:41, Bruno Friedmann <bruno(at)ioda-net(dot)ch> a écrit :
> On 11/01/2010 12:25 PM, Cédric Villemain wrote:
>> Le 1 novembre 2010 12:17, Bruno Friedmann <bruno(at)ioda-net(dot)ch> a écrit :
>>> On 11/01/2010 11:38 AM, Olivier Ducteil wrote:
>>>> select axe_x.x as p0x, axe_y.y as p0y,
>>>>  axe_x.x-10 as p1x,
>>>>  axe_y.y-10 as p1y,
>>>>
>>>>  axe_x.x+10 as p2x,
>>>>  axe_y.y-10 as p2y,
>>>>
>>>>  axe_x.x+10 as p3x,
>>>>  axe_y.y+10 as p3y,
>>>>
>>>>  axe_x.x-10 as p4x,
>>>>  axe_y.y+10 as p4y
>>>>
>>>>  from (select generate_series(0, 5000, 5)::numeric(12,4) as x limit 100) axe_x,
>>>>  (select generate_series(0, 5000, 5)::numeric(12,4) as y limit 100) axe_y
>>>> limit 100
>>>
>>> Merci Olivier, mais en fait non ... avec ta requète les valeurs x,y sont générés, moi je dois juste "coller" un numéro de
>>> kilomètre issue du generate_series à une autre requète
>>>
>>>
>>> premier résultat
>>> x,y,p0x,p0y....
>>> 2575205.7400;1230076.2300;2575195.7400;1230066.2300;2575215.7400;1230066.2300;2575215.7400;1230086.2300;2575195.7400;1230086.2300
>>> 2575205.7800;1230076.0400;2575195.7800;1230066.0400;2575215.7800;1230066.0400;2575215.7800;1230086.0400;2575195.7800;1230086.0400
>>> 2575205.8200;1230075.8300;2575195.8200;1230065.8300;2575215.8200;1230065.8300;2575215.8200;1230085.8300;2575195.8200;1230085.8300
>>>
>>> generate
>>> km
>>> 0.0000
>>> 5.0000
>>> 10.0000
>>>
>>> et là c'est très con je veux mettre les km comme première colone du précedent résultat
>>
>> un exemple précis de la sortie attendue  pourrait aider.
>> Si j'ai bien suivi tu veux quelque chose comme ceci :
>>
>> select *, (rank() over (order by id)) * 5::numeric(12,4) from foo;
>>
>
> Bon la freebeer va à Cédric :-)

Yeah !

>
> Joli le coup de la fonction window ( j'avais ça sur mon plan d'étude pour après pgday.eu )

Oui les WITH et CTE ca simplifie beaucoup de choses.

>
> Voilà la requète adaptée
>
> select (rank() over (order by lid.p0x) ) * 5::numeric(12,4), lid.* from
>  (
> select
>  x as p0x, y as p0y,
>  x-10 as p1x, y-10 as p1y,
>  x+10 as p2x, y-10 as p2y,
>  x+10 as p3x, y+10 as p3y,
>  x-10 as p4x, y+10 as p4y
>  from lidar
> limit 100
> ) as lid
>

la requête imbriquée est facultative (le over(order by x) se charge de 'ça') :

select (rank() over (order by x) ) * 5::numeric(12,4),
x as p0x, y as p0y,
x-10 as p1x, y-10 as p1y,
x+10 as p2x, y-10 as p2y,
x+10 as p3x, y+10 as p3y,
x-10 as p4x, y+10 as p4y
from lidar
limit 100

> avec les résultats qui vont bien
>
> 5.0000;2578034.3700;1231158.6800;2578024.3700;1231148.6800;2578044.3700;1231148.6800;2578044.3700;1231168.6800;2578024.3700;1231168.6800
> 10.0000;2578034.3900;1231158.4700;2578024.3900;1231148.4700;2578044.3900;1231148.4700;2578044.3900;1231168.4700;2578024.3900;1231168.4700
> 15.0000;2578034.4100;1231158.2300;2578024.4100;1231148.2300;2578044.4100;1231148.2300;2578044.4100;1231168.2300;2578024.4100;1231168.2300
> 20.0000;2578034.4300;1231158.0000;2578024.4300;1231148.0000;2578044.4300;1231148.0000;2578044.4300;1231168.0000;2578024.4300;1231168.0000
> 25.0000;2578034.4800;1231157.9000;2578024.4800;1231147.9000;2578044.4800;1231147.9000;2578044.4800;1231167.9000;2578024.4800;1231167.9000
>
> Superbe ...
>
>
> --
>
> Bruno Friedmann (irc:tigerfoot)
> Ioda-Net Sàrl www.ioda-net.ch
>  openSUSE Member
>    User www.ioda.net/r/osu
>    Blog www.ioda.net/r/blog
>  fsfe fellowship www.fsfe.org
> GPG KEY : D5C9B751C4653227
> vcard : http://it.ioda-net.ch/ioda-net.vcf
>
> --
> Sent via pgsql-fr-generale mailing list (pgsql-fr-generale(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-fr-generale
>

--
Cédric Villemain               2ndQuadrant
http://2ndQuadrant.fr/     PostgreSQL : Expertise, Formation et Support

In response to

Responses

Browse pgsql-fr-generale by date

  From Date Subject
Next Message Olivier Ducteil 2010-11-02 00:37:50 RE: [pgsql-fr-generale] Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] lié un generate_series et un autre select
Previous Message Bruno Friedmann 2010-11-01 11:41:51 Re: [pgsql-fr-generale] Re: [pgsql-fr-generale] lié un generate_series et un autre select