Received: from nts1.rtp.epa.gov (nts1.rtp.epa.gov [134.67.208.208]) by hub.org (8.10.1/8.10.1) with ESMTP id e7BG4QG29421 for ; Fri, 11 Aug 2000 12:04:26 -0400 (EDT) Received: from epamail.epa.gov (IDENT:mvs@wolfpack.rtpnc.epa.gov [134.67.139.59]) by nts1.rtp.epa.gov (8.9.3/8.9.3) with ESMTP id MAA23398; Fri, 11 Aug 2000 12:07:44 -0400 (EDT) Message-ID: <399423E4.BECD53E5@epamail.epa.gov> Date: Fri, 11 Aug 2000 12:03:48 -0400 From: Mark Volpe X-Mailer: Mozilla 4.74 [en] (X11; U; Linux 2.2.14-15mdk i586) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane CC: pgsql-sql@postgresql.org Subject: Re: Rules aren't doing what I expect References: <399180FD.2ACF8B2D@epamail.epa.gov> <2085.966003030@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200008/76 Tom Lane wrote: > > Queries added by non-INSTEAD rules are always performed before the > initially-given query, so you're right, the rule will see the unmodified > value. > > I'd suggest folding the log-entry-making into your trigger, actually. > If you have a trigger anyway then the insert into t1_log is only one > more line in that trigger procedure... > > regards, tom lane Thanks for the explanation, Tom. I left out part of my story though. :) I would like normal users to be able to modify t1 but not t1_log, and doing what you said would require INSERT permission on t1_log. So what I did was go ahead and allow INSERT permission, but create before and after triggers on t1_log that check the inserted values against reality... but that brings up another question - If I do an UPDATE on t1, it calls a trigger which eventually does: INSERT INTO t1_log VALUES(OLD.a, NEW.a); If t1_log has before and after triggers, the before trigger will always see the old row in t1, and the after trigger will always see the new data, right? At least that's what I'm seeing. The "visibility of data changes" document was kinda confusing... Mark