Обсуждение: Re: update behavior
> On Jun 19, 2025, at 11:34 AM, Scott Ribe <scott_ribe@elevated-dev.com> wrote: > >> On Jun 19, 2025, at 11:31 AM, David G. Johnston <david.g.johnston@gmail.com> wrote: >> >> Correct. You need a trigger to prevent the update. There is one provided: suppress_redundant_updates_trigger() > > Or, in my case that prompted this question, I need a WHERE clause for the ON CONFLICT UPDATE... Wait, should suppress_redundant_updates_trigger be used even in this case? Would it suppress the update before the constraintchecks and invocation of the ON CONFLICT clause???
> On Jun 19, 2025, at 11:39 AM, Scott Ribe <scott_ribe@elevated-dev.com> wrote: > >> On Jun 19, 2025, at 11:34 AM, Scott Ribe <scott_ribe@elevated-dev.com> wrote: >> >>> On Jun 19, 2025, at 11:31 AM, David G. Johnston <david.g.johnston@gmail.com> wrote: >>> >>> Correct. You need a trigger to prevent the update. There is one provided: suppress_redundant_updates_trigger() >> >> Or, in my case that prompted this question, I need a WHERE clause for the ON CONFLICT UPDATE... > > Wait, should suppress_redundant_updates_trigger be used even in this case? Would it suppress the update before the constraintchecks and invocation of the ON CONFLICT clause??? Or no, duh, this starts with an INSERT where that won't be run, there is no UPDATE until after the constraint violation,but then at that point it would suppress the update?
Scott Ribe <scott_ribe@elevated-dev.com> writes: > On Jun 19, 2025, at 11:39 AM, Scott Ribe <scott_ribe@elevated-dev.com> wrote: >> Wait, should suppress_redundant_updates_trigger be used even in this case? Would it suppress the update before the constraintchecks and invocation of the ON CONFLICT clause??? > Or no, duh, this starts with an INSERT where that won't be run, there is no UPDATE until after the constraint violation,but then at that point it would suppress the update? I believe we fire ON UPDATE triggers when an INSERT ON CONFLICT takes an UPDATE action, so it should do what you want. The overhead tradeoff is yours to make. regards, tom lane
> On Jun 19, 2025, at 12:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > I believe we fire ON UPDATE triggers when an INSERT ON CONFLICT > takes an UPDATE action, so it should do what you want. Tested, and confirmed, this morning.