Detection of which attributes should get set in update trigger

From: Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Detection of which attributes should get set in update trigger
Date: 2023-11-10 09:46:05
Message-ID: b096c272-b2b8-470e-8eca-7164adabfca7@gelassene-pferde.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all

I have a view, that is a join over 4 tables (the setup of the rule
question). I want to update the central table over the view (by an
instead-of trigger). How can I determine, whether an attribute should
get set to NULL, "new.XYZ is null" or whether it should be left alone.
Is there a leave-me-alone function determining, whether an attribute is
in the set clause of an update statement. I am thinking along the line
code in the trigger function like

update TABLE
   set XYZ = case
                  when leave-me-alone (new.XYZ) then old.XYZ
                  else new.XYZ
             end;

And what about the where condition... hm, guess I am a bit confused.

Kind regards

Thiemo

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2023-11-10 13:35:01 Re: Detection of which attributes should get set in update trigger
Previous Message Adrian Klaver 2023-11-09 17:50:24 Re: Rule system (and triggers)