Re: Trigger with conditional predicates

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Trigger with conditional predicates
Date: 2021-01-01 16:05:26
Message-ID: 7097609B-DCC8-49B8-932C-35A3D7D6A405@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Jan 1, 2021, at 07:56, Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)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 based on 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(at)thebuild(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2021-01-01 16:27:47 Re: Trigger with conditional predicates
Previous Message Dirk Mika 2021-01-01 15:56:32 Trigger with conditional predicates