pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCreate Calendar
3+ messages / 3 participants
[nested] [flat]
* Create Calendar
@ 2004-12-10 19:26 Muhyiddin A.M Hayat <middink@indo.net.id>
2004-12-11 04:11 ` Re: Create Calendar Michael Fuhr <mike@fuhr.org>
2004-12-11 11:55 ` Re: Create Calendar Joe Conway <mail@joeconway.com>
0 siblings, 2 replies; 3+ messages in thread
From: Muhyiddin A.M Hayat @ 2004-12-10 19:26 UTC (permalink / raw)
To: pgsql-sql
Dear All,
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Create Calendar
2004-12-10 19:26 Create Calendar Muhyiddin A.M Hayat <middink@indo.net.id>
@ 2004-12-11 04:11 ` Michael Fuhr <mike@fuhr.org>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Fuhr @ 2004-12-11 04:11 UTC (permalink / raw)
To: Muhyiddin A.M Hayat <middink@indo.net.id>; +Cc: pgsql-sql
On Sat, Dec 11, 2004 at 03:26:33AM +0800, 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.
You could write a function that returns SETOF DATE. Some sections
of the documentation you'll want to study are:
"Data Types" chapter, "Date/Time Types" section
"Functions and Operators" chapter, "Date/Time Functions and
Operators" section
"PL/pgSQL - SQL Procedural Language" chapter, especially the
"Control Structures" section
If you have trouble then please post what you've tried with an
explanation of how you'd like it to work and a description of
what actually happens.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Create Calendar
2004-12-10 19:26 Create Calendar Muhyiddin A.M Hayat <middink@indo.net.id>
@ 2004-12-11 11:55 ` Joe Conway <mail@joeconway.com>
1 sibling, 0 replies; 3+ messages in thread
From: Joe Conway @ 2004-12-11 11:55 UTC (permalink / raw)
To: Muhyiddin A.M Hayat <middink@indo.net.id>; +Cc: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-12-11 11:55 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-12-10 19:26 Create Calendar Muhyiddin A.M Hayat <middink@indo.net.id>
2004-12-11 04:11 ` Michael Fuhr <mike@fuhr.org>
2004-12-11 11:55 ` Joe Conway <mail@joeconway.com>
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