pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedRES: help with generation_series in pg10
3+ messages / 2 participants
[nested] [flat]
* RES: help with generation_series in pg10
@ 2018-01-09 16:14 Márcio A. Sepp <marcio@zyontecnologia.com.br>
0 siblings, 2 replies; 3+ messages in thread
From: Márcio A. Sepp @ 2018-01-09 16:14 UTC (permalink / raw)
To: 'Alvaro Herrera' <alvherre@alvh.no-ip.org>; +Cc: pgsql-general
> > 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');
in some case I need to order the timestamp data field and in others I just
need an interval. So, in some moments an random data already help me and in
others it is necessary to have both fields aligned.
thanks
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: RES: help with generation_series in pg10
@ 2018-01-09 16:23 Alvaro Herrera <alvherre@alvh.no-ip.org>
parent: Márcio A. Sepp <marcio@zyontecnologia.com.br>
1 sibling, 0 replies; 3+ messages in thread
From: Alvaro Herrera @ 2018-01-09 16:23 UTC (permalink / raw)
To: Márcio A. Sepp <marcio@zyontecnologia.com.br>; +Cc: pgsql-general
Márcio A. Sepp wrote:
> > 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');
>
>
> in some case I need to order the timestamp data field and in others I just
> need an interval. So, in some moments an random data already help me and in
> others it is necessary to have both fields aligned.
Maybe something like this
select *
from generate_series(date '2018-01-01 10:00', '2018-01-02 10:00', '10 hours')
with ordinality;
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 3+ messages in thread
* RES: help with generation_series in pg10
@ 2018-01-10 15:22 Márcio A. Sepp <marcio@zyontecnologia.com.br>
parent: Márcio A. Sepp <marcio@zyontecnologia.com.br>
1 sibling, 0 replies; 3+ messages in thread
From: Márcio A. Sepp @ 2018-01-10 15:22 UTC (permalink / raw)
To: 'Merlin Moncure' <mmoncure@gmail.com>; +Cc: 'Alvaro Herrera' <alvherre@alvh.no-ip.org>; pgsql-general
> >> > 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;
Exactly what I need. Thank you so much!!!
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2018-01-10 15:22 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 16:14 RES: help with generation_series in pg10 Márcio A. Sepp <marcio@zyontecnologia.com.br>
2018-01-09 16:23 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-01-10 15:22 ` Márcio A. Sepp <marcio@zyontecnologia.com.br>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox