Re: help with generation_series in pg10

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Márcio A(dot) Sepp <marcio(at)zyontecnologia(dot)com(dot)br>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: help with generation_series in pg10
Date: 2018-01-10 14:28:44
Message-ID: CAHyXU0wh0bt-8QAjHHdH+SQQ4WdvVGWS8hT6deZMqXfenCYb-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 9, 2018 at 10:14 AM, Márcio A. Sepp
<marcio(at)zyontecnologia(dot)com(dot)br> wrote:
>
>> > how can i have the same in pg10 as i have had in pg 9.x?
>>
>> Move the function call to the FROM clause:
>>
>> select g, (g - 1) % 5 + 1 from generate_series(1, 10) g;
>
> thank you. That is exact what i need.
>
>
>> > I need it to date type to... if possible.
>>
>> There is a generate_series() variant that can return dates (more
>> precisely, timestamp with time zone). But what exactly would you like
>> returned?
>
> In the past i use querys like this to generate some timestamp field:
> select generate_series (1, 10), generate_series('2018-01-01
> 10:00'::timestamp, '2018-01-02 10:00'::timestamp, '10 hours');

With the old behavior you're lucky this ever worked at all. Doing
this kind of stuff, you want to write it with a single generate_series
driver if you can or as a cross product:

select
a, b,c
from generate_series(1,3) a
cross join generate_series(1,4) b
cross join generate_series(1,2) c;

The old behavior presented 'least common multiple' which was very
surprising in that it sometimes worked like cross product but
sometimes didn't depending on specific numbers chosen.

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Márcio A. Sepp 2018-01-10 15:22:07 RES: help with generation_series in pg10
Previous Message Merlin Moncure 2018-01-10 14:19:07 Re: help with generation_series in pg10