best way: diary functions.

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: best way: diary functions.
Date: 2007-04-03 12:25:50
Message-ID: 200704031325.50542.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Carlos Santos 2007-04-03 12:48:41 LOCK command inside a TRANSACTION
Previous Message A. Kretschmer 2007-04-03 10:40:12 Re: Serial