X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2626053E00 for ; Fri, 22 Apr 2005 05:42:32 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52255-08 for ; Fri, 22 Apr 2005 08:42:28 +0000 (GMT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 6009C53E01 for ; Fri, 22 Apr 2005 05:42:25 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Fri Apr 22 10:42:19 2005 +0200 Received: from rodos.fzk.de (resy6.fzk.de [141.52.68.10]) by resy5.fzk.de (8.12.7/8.12.7/SuSE Linux 0.6) with ESMTP id j3M8gIsG003189; Fri, 22 Apr 2005 10:42:18 +0200 Message-ID: <4268B8E9.B4085A19@rodos.fzk.de> Date: Fri, 22 Apr 2005 10:42:17 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: weigelt@metux.de Cc: pgsql-sql Subject: Re: RULE for mtime recording References: <20050422015852.GA1298@nibiru.borg.metux.de> Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS - amavis-milter (http://www.amavis.org/) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.029 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/319 X-Sequence-Number: 21212 Enrico Weigelt wrote: > > Hi folks, > > I'd like to write an update rule, which touches the a mtime field > (=current_timestamp) on normal update - when the mtime field isnt > explicitly set. If the update query explictly sets an mtime value, > this value has to be let through. > > my tables look like: > > -- base class > CREATE TABLE inode > ( > inode_id oid not null default nextval('inode_id_seq'), > mtime timestamp not null default current_timestamp > ); > > -- example class > CREATE TABLE foo > ( > bar text > ) INHERITS ( inode ); > > now if I do > > UPDATE foo SET bar = 'xyz' WHERE ... > > the mtime should be set to the current time, but on > > UPDATE foo SET bar = '123', mtime = '2001-09-11' WHERE ... > > we shall have 9/11 as mtime. > > Is this possible with rules ? > > thx Just ReadingTFM, I'd say this should do: CREATE OR REPLACE RULE foo_update_mtime_is_null AS ON UPDATE TO foo WHERE mtime IS NULL DO INSTEAD UPDATE foo SET bar = NEW.bar WHERE ... ; CREATE OR REPLACE RULE foo_update_mtime_is_not_null AS ON UPDATE TO foo WHERE mtime IS NOT NULL DO INSTEAD UPDATE foo SET bar = NEW.bar, mtime = NEW.mtime WHERE ... ; I have very few experience with rules, so if this works, please let me know. Regards, Christoph > -- > --------------------------------------------------------------------- > Enrico Weigelt == metux IT service > > phone: +49 36207 519931 www: http://www.metux.de/ > fax: +49 36207 519932 email: contact@metux.de > cellphone: +49 174 7066481 > ---------------------------------------------------------------------