Re: knowing which columns have beend UPDATEd inside a TRIGGER?

From: Tomas Berndtsson <tomas(at)nocrew(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: ldm(at)apartia(dot)ch, pgsql-sql(at)hub(dot)org
Subject: Re: knowing which columns have beend UPDATEd inside a TRIGGER?
Date: 2000-10-25 07:21:52
Message-ID: 80zojtgzcf.fsf@junk.nocrew.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Louis-David Mitterrand <cunctator(at)apartia(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Aarni Ruuhimäki 2000-10-25 09:51:00 INNER JOIN query with Postgre 6.5
Previous Message Louis-David Mitterrand 2000-10-25 06:23:20 Re: knowing which columns have beend UPDATEd inside a TRIGGER?

Browse pgsql-sql by date

  From Date Subject
Next Message Blaise Carrupt 2000-10-25 10:48:38 Get a time from a char column
Previous Message Louis-David Mitterrand 2000-10-25 06:23:20 Re: knowing which columns have beend UPDATEd inside a TRIGGER?