best way: diary functions. - Mailing list pgsql-sql

From Gary Stainburn
Subject best way: diary functions.
Date
Msg-id 200704031325.50542.gary.stainburn@ringways.co.uk
Whole thread Raw
Responses Solved - best way: diary functions.  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
List pgsql-sql
Hi folks

I've got 2 tables, 

availabiliy
~~~~~~~

stdate    date
edate    date
workdays    integer
comments    text

example record
2007-03-01    2007-03-07     5    Please can I have alternate days


roster
~~~~
rdate    date
rdiag    varchar(10)

example
2007-03-01    B12
2007-03-03    B11
2006-03-05    B12
2007-03-07    B13

What would be the best way to create a view to list every date within a range 
giving either rostered, available but not rostered, and not available?

I've read through the docs and created a function (below) to return every date 
within a range, but I can't get my head round converting that to a query.

Although I'm doing this as a learning exercise, it will be used in a web site 
I'm developing so comments on speed and efficiency would also be welcome.

Gary

create or replace function date_range(fdate date,tdate date) returns setof 
date
AS $PROC$
DECLARE wdate date;
BEGIN return next fdate; wdate:=fdate+1; while wdate <= tdate LOOP   return next wdate;   wdate:=wdate+1; end LOOP;
return;
END;
$PROC$ LANGUAGE plpgsql;



-- 
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


pgsql-sql by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Serial
Next
From: Carlos Santos
Date:
Subject: LOCK command inside a TRANSACTION