X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9DD40D1B531 for ; Sun, 4 Jan 2004 18:55:34 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 02288-09 for ; Sun, 4 Jan 2004 14:54:45 -0400 (AST) Received: from web13808.mail.yahoo.com (web13808.mail.yahoo.com [216.136.175.18]) by svr1.postgresql.org (Postfix) with SMTP id 396C4D1B4A7 for ; Sun, 4 Jan 2004 14:54:44 -0400 (AST) Message-ID: <20040104185444.78502.qmail@web13808.mail.yahoo.com> Received: from [68.46.224.205] by web13808.mail.yahoo.com via HTTP; Sun, 04 Jan 2004 10:54:44 PST Date: Sun, 4 Jan 2004 10:54:44 -0800 (PST) From: Chris Gamache Reply-To: cgg007@yahoo.com Subject: Historic Query using a view/function ? To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/18 X-Sequence-Number: 16411 ...Postgresql 7.2... I'm building the history of a table using rules. I've been trying to figure out a way to select on a table as it would have appeared at a point-in-time. I can't seem to wrap my brain around the problem, tho. Given some tables CREATE TABLE list ( num int4 NOT NULL, name varchar(50), type varchar(50), modified timestamptz DEFAULT ('now'::text)::timestamp(6) with time zone, CONSTRAINT list_pkey PRIMARY KEY (num) ) WITH OIDS; CREATE TABLE list_log ( num int4 NOT NULL, name varchar(50), type varchar(50), modified timestamptz DEFAULT ('now'::text)::timestamp(6) with time zone, mod_type varchar(3), log_date timestamptz DEFAULT ('now'::text)::timestamp(6) with time zone ) WITH OIDS; And some rules... CREATE RULE list_del AS ON DELETE TO list DO INSERT INTO list_log (num, name, type, modified, mod_type) VALUES (old.num, old.name, old.type, old.modified, 'D'::"varchar"); CREATE RULE list_upd AS ON UPDATE TO list WHERE ((old.name <> new.name) OR (old.type <> new.type)) DO INSERT INTO list_log (num, name, type, modified, mod_type) VALUES (old.num, old.name, old.type, old.modified, 'U'::"varchar"); It'd be great to be able to do something like... SELECT * FROM hist_list('10/10/2003'::date) WHERE name like '%Jones'; ... I don't think Functions can return tables in 7.2 ... Can anyone think of a way around this? CG __________________________________ Do you Yahoo!? Find out what made the Top Yahoo! Searches of 2003 http://search.yahoo.com/top2003