Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id A8C3C9FB459 for ; Tue, 3 Apr 2007 09:46:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 01140-08 for ; Tue, 3 Apr 2007 09:46:24 -0300 (ADT) X-Greylist: delayed 00:19:14.461097 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 3C41A9FB797 for ; Tue, 3 Apr 2007 09:46:17 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail.ringways.co.uk (unknown [80.193.83.130]) by svr4.postgresql.org (Postfix) with ESMTP id BD3E75AF0B2 for ; Tue, 3 Apr 2007 12:27:01 +0000 (GMT) Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.62) (envelope-from ) id 1HYi08-0004RE-Vl for pgsql-sql@postgresql.org; Tue, 03 Apr 2007 13:20:41 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: best way: diary functions. Date: Tue, 3 Apr 2007 13:25:50 +0100 User-Agent: KMail/1.9.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200704031325.50542.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200704/25 X-Sequence-Number: 28025 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