Re: TRIGGER Question

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: sbob <sbob(at)quadratum-braccas(dot)com>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: TRIGGER Question
Date: 2021-05-28 05:40:19
Message-ID: CAKFQuwbxA_d39=hmPTGrhQR85-5e2OFJneLi0ZA1kA9LSzaTvg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Thu, May 27, 2021 at 9:31 PM sbob <sbob(at)quadratum-braccas(dot)com> wrote:

> I want to create a trigger function that can set a value for a column if
> the column was not specified in the update statement.
> [...]
>
> However if the row to be updated already has a value for last_updated_by
> even if the last_updated_by column is not specified in the update
> statement, then the "IF NEW.last_updated_by IS NULL THEN" is never fired..
>
>
> Thoughts?
>

Not specifying a column in an update is shorthand for "leave the column
unchanged". There isn't a way for you to make it mean something else - you
only get to see that OLD and NEW are equal.

Thus, your requirement is not possible as described. And if you have to
allow for arbitrary update commands your requirement is going to be
impossible to enforce. Otherwise, you could make all updates go through
procedures/functions and enforce the requirement there.

David J.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Yambu 2021-05-28 09:20:12 LDAP autos in postgres
Previous Message sbob 2021-05-28 04:31:38 TRIGGER Question