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

From Christophe Pettus
Subject Re: Trigger with conditional predicates
Date
Msg-id 7097609B-DCC8-49B8-932C-35A3D7D6A405@thebuild.com
Whole thread Raw
In response to Trigger with conditional predicates  (Dirk Mika <Dirk.Mika@mikatiming.de>)
Responses Re: Trigger with conditional predicates
Re: Trigger with conditional predicates
List pgsql-general

> On Jan 1, 2021, at 07:56, Dirk Mika <Dirk.Mika@mikatiming.de> wrote:
> 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;

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

--
-- Christophe Pettus
   xof@thebuild.com




pgsql-general by date:

Previous
From: Dirk Mika
Date:
Subject: Trigger with conditional predicates
Next
From: Tom Lane
Date:
Subject: Re: Trigger with conditional predicates