Re: update behavior - Mailing list pgsql-admin

From Scott Ribe
Subject Re: update behavior
Date
Msg-id 54495544-60AB-4CC8-9F47-78B33F4D99C4@elevated-dev.com
Whole thread Raw
Responses Re: update behavior
List pgsql-admin
> On Jun 19, 2025, at 11:54 AM, Rui DeSousa <rui@crazybean.net> wrote:
>
>
>
>> On Jun 19, 2025, at 1:23 PM, Scott Ribe <scott_ribe@elevated-dev.com> wrote:
>>
>> I believe that if I UPDATE a row with the same values that it already has, this still dirties pages, writes the row,
generatesa WAL entry. There is no shortcut in the processing that's "hey, there's not really a change here, we'll just
leavestorage alone". 
>>
>> Is this correct?
>>
>
> Correct, but it can be avoided.
>
> No update occurs in this case:.
>
> update foo
>   set data = ‘hello world’
> where id = 33
>    and data is distinct from ‘hello world’
> ;

That was my thought when I posted the original question, when I didn't know about suppress_redundant_updates_trigger.
NowI'm thinking the trigger is an option. 

- The trigger has the advantage that one doesn't have to maintain the WHERE clause--especially if the list of columns
islong. 
- It has the disadvantage of always running, even in contexts where it might not be needed.





pgsql-admin by date:

Previous
From: Rui DeSousa
Date:
Subject: Re: update behavior
Next
From: Ron Johnson
Date:
Subject: Re: update behavior