Skip site navigation (1) Skip section navigation (2)

Re: Create Calendar

From: Joe Conway <mail(at)joeconway(dot)com>
To: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Create Calendar
Date: 2004-12-11 11:55:44
Message-ID: 41BAE040.9040207@joeconway.com (view raw or flat)
Thread:
Lists: pgsql-sql
Muhyiddin A.M Hayat wrote:
> How to create Calendar using Function/View. 
> For example i would like to display date 2004-12-01 to 2004-12-20. 
> 
> date
> ------
> 2004-12-01 
> 2004-12-02 
> 2004-12-03 
> 2004-12-04 
> 2004-12-05
> ..................
> .................. 
> 2004-12-20 


-- Use in Postgres 7.4.x and earlier.
-- In Postgres 8.0.0 generate_series() is a built-in function
CREATE OR REPLACE FUNCTION generate_series(int, int) RETURNS setof int AS '
  BEGIN
   FOR i IN $1..$2 LOOP
    RETURN NEXT i;
   END LOOP;
   RETURN;
  END;
' LANGUAGE plpgsql;

select '2004/12/01'::date + f1 from generate_series(0, 19) as t(f1);
   ?column?
------------
  2004-12-01
  2004-12-02
  2004-12-03
  2004-12-04
  2004-12-05
  [...]
  2004-12-20
(20 rows)

HTH,

Joe

In response to

pgsql-sql by date

Next:From: Ian BarwickDate: 2004-12-11 12:25:37
Subject: Re: replacing mysql enum
Previous:From: Josh BerkusDate: 2004-12-11 05:11:28
Subject: Re: Cast NULL into Timestamp?

Privacy Policy | About PostgreSQL
Copyright © 1996-2013 The PostgreSQL Global Development Group