Thread: generating date sequences

generating date sequences

From
Patrick Scharrenberg
Date:
Hi!
Is there a simple way to generate sequences of dates like the following?"2008-07-03 00:00:00""2008-07-04
00:00:00""2008-07-0500:00:00""2008-07-06 00:00:00"
 


I'd like to join a table to aggregate the number of items for each day
(each item has a timestamp).
For some days however there are no items, resulting in no row instead of
a row with zero items.
I'd like to fill these empty rows.

I hope I could make my problem clear?!

Best regards
Patrick


Re: generating date sequences

From
"A. Kretschmer"
Date:
am  Mon, dem 20.10.2008, um 15:24:38 +0200 mailte Patrick Scharrenberg folgendes:
> Hi!
> Is there a simple way to generate sequences of dates like the following?
>     "2008-07-03 00:00:00"
>     "2008-07-04 00:00:00"
>     "2008-07-05 00:00:00"
>     "2008-07-06 00:00:00"
> 

Sure:

test=# select '2008-07-03'::date + s * '1day'::interval from
generate_Series(1,10) s;     ?column?
---------------------2008-07-04 00:00:002008-07-05 00:00:002008-07-06 00:00:002008-07-07 00:00:002008-07-08
00:00:002008-07-0900:00:002008-07-10 00:00:002008-07-11 00:00:002008-07-12 00:00:002008-07-13 00:00:00
 
(10 rows)


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


Re: generating date sequences

From
Patrick Scharrenberg
Date:
Hi!

>> Is there a simple way to generate sequences of dates like the following?
> Sure:
> test=# select '2008-07-03'::date + s * '1day'::interval from
> generate_Series(1,10) s;


Thanks! Thats what I was searching for.

You saved my day from manually adding missing dates in a huge excel sheet!

So thank you again!

P. Scharrenberg