pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Muhyiddin A.M Hayat <middink@indo.net.id>
Cc: pgsql-sql@postgresql.org
Subject: Re: Create Calendar
Date: Sat, 11 Dec 2004 03:55:44 -0800
Message-ID: <41BAE040.9040207@joeconway.com> (raw)
In-Reply-To: <003801c4deee$451eb6c0$1f00a8c0@middinks>
References: <003801c4deee$451eb6c0$1f00a8c0@middinks>

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



view thread (3+ messages)

Message-ID: <41BAE040.9040207@joeconway.com>
Permalink:  ../41BAE040.9040207@joeconway.com/
Also on:    postgresql.org/message-id/41BAE040.9040207@joeconway.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mail@joeconway.com, middink@indo.net.id
  Subject: Re: Create Calendar
  In-Reply-To: <41BAE040.9040207@joeconway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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