Re: Trigger with conditional predicates - Mailing list pgsql-general

From Dirk Mika
Subject Re: Trigger with conditional predicates
Date
Msg-id 28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de
Whole thread Raw
In response to Re: Trigger with conditional predicates  (Christophe Pettus <xof@thebuild.com>)
Responses Re: Trigger with conditional predicates  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
> > In particular, columns are populated with values if they are not specified in the update statement which is used.
> > Usually with an expression like this:
> >
> >      IF NOT UPDATING('IS_CANCELED')
> >      THEN
> >         :new.is_canceled := ...;
> >      END IF;
> >
> > I have not found anything similar in PostgreSQL. What is the common approach to this problem?
>
> PostgreSQL doesn't have an exact equivalent.  Typically, the OLD and NEW values are compared and then action is taken
basedon that.  For example, in PL/pgSQL:
 
>
> IF NEW.is_canceled IS NOT DISTINCT FROM OLD.is_canceled THEN
>NEW.is_canceled := etc etc ;
> ENDIF;

Unfortunately, this doesn't quite fit the logic I need. I don't need to know if the value was changed, but if the
applicationthat sent the UPDATE statement knows the column or not.
 
In our case, a number of different applications access the database, which may or may not know the column depending on
theversion.
 
And it is also regularly the case that SQL statements are executed directly in an SQL client by hand. And in the event
thatthe column was not specified in these statements, a trigger is supposed to fill the value.
 

> There's currently no way to detect if the column was simply not mentioned at all in the UPDATE statement.

Hmm, that's odd.

BR
Dirk



--
Dirk Mika
Software Developer

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany

fon +49 2202 2401-1197
dirk.mika@mikatiming.de
www.mikatiming.de

AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika



pgsql-general by date:

Previous
From: Dirk Mika
Date:
Subject: Re: Trigger with conditional predicates
Next
From: Alban Hertroys
Date:
Subject: Re: Trigger with conditional predicates