pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Dirk Mika <Dirk.Mika@mikatiming.de>
To: Christophe Pettus <xof@thebuild.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Trigger with conditional predicates
Date: Sat, 2 Jan 2021 07:36:21 -0800
Message-ID: <0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com> (raw)
In-Reply-To: <28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de>
References: <A4A3D4D4-B8C9-4ED2-B10D-0A908D639F99@mikatiming.de>
	<7097609B-DCC8-49B8-932C-35A3D7D6A405@thebuild.com>
	<28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de>

On 1/2/21 2:23 AM, Dirk Mika 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;
> 
> Unfortunately, this doesn't quite fit the logic I need. I don't need to know if the value was changed, but if the application that 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 the version.
> And it is also regularly the case that SQL statements are executed directly in an SQL client by hand. And in the event that the 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.

See thread below:

https://www.postgresql.org/message-id/VisenaEmail.26.7cbf2947c8d23ceb.1769a2755ff%40tc7-visena

> 
> 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
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (11+ messages)  latest in thread

Message-ID: <0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com>
Permalink:  ../0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com/
Also on:    postgresql.org/message-id/0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, Dirk.Mika@mikatiming.de, xof@thebuild.com
  Subject: Re: Trigger with conditional predicates
  In-Reply-To: <0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com>
  References: <A4A3D4D4-B8C9-4ED2-B10D-0A908D639F99@mikatiming.de> <7097609B-DCC8-49B8-932C-35A3D7D6A405@thebuild.com> <28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de> <0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox