Received: from junk.nocrew.org (mail@[212.73.17.42]) by hub.org (8.10.1/8.11.0) with ESMTP id e9P7NIO53856 for ; Wed, 25 Oct 2000 03:23:21 -0400 (EDT) (envelope-from tomas@junk.nocrew.org) Received: from tomas by junk.nocrew.org with local (Exim 3.12 #1 (Debian)) id 13oKsi-0007T5-00; Wed, 25 Oct 2000 09:21:52 +0200 To: Tom Lane Cc: ldm@apartia.ch, pgsql-sql@hub.org Subject: Re: knowing which columns have beend UPDATEd inside a TRIGGER? References: <20001024155506.A775@styx> <26414.972427863@sss.pgh.pa.us> From: Tomas Berndtsson Date: 25 Oct 2000 09:21:52 +0200 In-Reply-To: Tom Lane's message of "Tue, 24 Oct 2000 18:51:03 -0400" Message-ID: <80zojtgzcf.fsf@junk.nocrew.org> Lines: 25 User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200010/217 X-Sequence-Number: 1881 Tom Lane writes: > Louis-David Mitterrand writes: > > Is there a way to know which columns are being UPDATEd or INSERTEd from > > inside a trigger, either in C or pl/pgsql? > > Huh? An INSERT always inserts all columns, by definition. Some of them > might be null and/or equal to their default values, but they're all > there. > > For an UPDATE, you could check to see whether old.col = new.col. > This would miss the case where an UPDATE command is explicitly setting > a column to the same value it already had; dunno if you care or not. Another way, is to have an extra boolean column called "updated", or something like that. When you do the UPDATE, you make sure that always updates the row with a 't' in that column. Then you do whatever you need to do with the newly updated rows, and when done, you run another UPDATE to set all rows to 'f' in the "updated" column. Takes two updates, but might sometimes be easier than comparing the rows to see if they've changed. Tomas