X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1052A3A62FA for ; Fri, 28 Jan 2005 15:47:24 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64137-07 for ; Fri, 28 Jan 2005 15:47:13 +0000 (GMT) Received: from lucifer.oficina (unknown [200.68.121.201]) by svr1.postgresql.org (Postfix) with ESMTP id 306943A6307 for ; Fri, 28 Jan 2005 15:47:11 +0000 (GMT) Received: from localhost (localhost.akyasociados.com.ar [127.0.0.1]) by lucifer.oficina (8.13.1/8.12.10) with ESMTP id j0SFkq49093761; Fri, 28 Jan 2005 12:46:52 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Received: from lucifer.oficina ([127.0.0.1]) by localhost (lucifer.oficina [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 92442-10; Fri, 28 Jan 2005 12:46:51 -0300 (ART) Received: from [192.168.1.168] (taz.oficina [192.168.1.168]) (authenticated bits=0) by lucifer.oficina (8.13.1/8.12.10) with ESMTP id j0SFkoK0093758; Fri, 28 Jan 2005 12:46:50 -0300 (ART) (envelope-from franco@akyasociados.com.ar) Message-ID: <41FA5E6A.50002@akyasociados.com.ar> Date: Fri, 28 Jan 2005 12:46:50 -0300 From: Franco Bruno Borghesi User-Agent: Mozilla Thunderbird 1.0 (X11/20041216) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Muhyiddin A.M Hayat" Cc: pgsql-sql@postgresql.org Subject: Re: Calendar Function References: <03a001c50545$6bd942d0$1f00a8c0@middinks> In-Reply-To: <03a001c50545$6bd942d0$1f00a8c0@middinks> Content-Type: multipart/alternative; boundary="------------000502020909030806010808" X-Virus-Scanned: by amavisd-new at akyasociados.com.ar X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.202 tagged_above=0 required=5 tests=AWL, HTML_60_70, HTML_MESSAGE, HTML_TITLE_EMPTY, RCVD_IN_SORBS_DUL X-Spam-Level: X-Archive-Number: 200501/310 X-Sequence-Number: 20098 This is a multi-part message in MIME format. --------------000502020909030806010808 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit maybe somthing like this: CREATE OR REPLACE FUNCTION calendar (DATE, DATE) RETURNS SETOF DATE LANGUAGE 'plpgsql' AS ' DECLARE v_from ALIAS FOR $1; v_to ALIAS FOR $2; v_current DATE DEFAULT v_from; BEGIN WHILE (v_current<=v_to) LOOP RETURN NEXT v_current; v_current:=v_current+1; END LOOP; RETURN; END; '; test it: SELECT * FROM calendar('2005-01-01', '2005-01-31'); Muhyiddin A.M Hayat wrote: > Dear All, > > How to create Calendar Function or Query. I would like to display date > form yyyy-mm-dd to yyyy-mm-dd or display date in one Month > > e.g: > > date > ------------ > 2005-01-01 > 2005-01-02 > 2005-01-03 > 2005-01-04 > 2005-01-05 > 2005-01-06 > 2005-01-07 > 2005-01-08 > 2005-01-09 > 2005-01-10 > 2005-01-11 > 2005-01-12 > 2005-01-13 > 2005-01-14 > 2005-01-15 > 2005-01-16 > 2005-01-17 > 2005-01-18 > 2005-01-19 > 2005-01-20 > 2005-01-21 > 2005-01-22 > 2005-01-23 > 2005-01-24 > 2005-01-25 > 2005-01-26 > 2005-01-27 > 2005-01-28 > 2005-01-29 > 2005-01-30 > 2005-01-31 > > --------------000502020909030806010808 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit maybe somthing like this:

CREATE OR REPLACE FUNCTION calendar (DATE, DATE) RETURNS SETOF DATE LANGUAGE 'plpgsql' AS '
DECLARE
    v_from ALIAS FOR $1;
    v_to ALIAS FOR $2;
    v_current DATE DEFAULT v_from;
BEGIN
    WHILE (v_current<=v_to) LOOP
        RETURN NEXT v_current;
        v_current:=v_current+1;
    END LOOP;
   
    RETURN;
END;
';

test it:
SELECT * FROM calendar('2005-01-01', '2005-01-31');


Muhyiddin A.M Hayat wrote:
Dear All,
 
How to create Calendar Function or Query. I would like to display date form yyyy-mm-dd to yyyy-mm-dd or display date in one Month
 
e.g:
 
    date
------------
 2005-01-01
 2005-01-02
 2005-01-03
 2005-01-04
 2005-01-05
 2005-01-06
 2005-01-07
 2005-01-08
 2005-01-09
 2005-01-10
 2005-01-11
 2005-01-12
 2005-01-13
 2005-01-14
 2005-01-15
 2005-01-16
 2005-01-17
 2005-01-18
 2005-01-19
 2005-01-20
 2005-01-21
 2005-01-22
 2005-01-23
 2005-01-24
 2005-01-25
 2005-01-26
 2005-01-27
 2005-01-28
 2005-01-29
 2005-01-30
 2005-01-31
 
 

--------------000502020909030806010808--