pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Berndtsson <tomas@nocrew.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: ldm@apartia.ch
Cc: pgsql-sql@hub.org
Subject: Re: knowing which columns have beend UPDATEd inside a TRIGGER?
Date: 25 Oct 2000 09:21:52 +0200
Message-ID: <80zojtgzcf.fsf@junk.nocrew.org> (raw)
References: <20001024155506.A775@styx>
	<26414.972427863@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.us> writes:

> Louis-David Mitterrand <cunctator@apartia.ch> 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



view thread (4+ messages)

Message-ID: <80zojtgzcf.fsf@junk.nocrew.org>
Permalink:  ../80zojtgzcf.fsf@junk.nocrew.org/
Also on:    postgresql.org/message-id/80zojtgzcf.fsf@junk.nocrew.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tomas@nocrew.org, tgl@sss.pgh.pa.us, ldm@apartia.ch, pgsql-sql@hub.org
  Subject: Re: knowing which columns have beend UPDATEd inside a TRIGGER?
  In-Reply-To: <80zojtgzcf.fsf@junk.nocrew.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox