pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Wheeler <hippysoyboy@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: How to avoid Trigger ping/pong / infinite loop
Date: Fri, 17 Feb 2023 06:42:39 +1100
Message-ID: <87FC4042-E7F1-4A53-AE60-1C84B5276713@gmail.com> (raw)
In-Reply-To: <CAKFQuwZb+jY2A_j2MjJszBmn8YPW1imwnjefGtjR2=1NiNqdAA@mail.gmail.com>
References: <CAKFQuwZb+jY2A_j2MjJszBmn8YPW1imwnjefGtjR2=1NiNqdAA@mail.gmail.com>


>> Are there techniques for situations like this?

Just have two triggers, one for each column, and ensure that if your trigger doesn’t change the value then it doesn’t do an update on the other column. Each time you do update both triggers will run but only one will make a change, so that will break the cycle

For insert case ensure the triggers do nothing if their source col is null

view thread (7+ messages)  latest in thread

Message-ID: <87FC4042-E7F1-4A53-AE60-1C84B5276713@gmail.com>
Permalink:  ../87FC4042-E7F1-4A53-AE60-1C84B5276713@gmail.com/
Also on:    postgresql.org/message-id/87FC4042-E7F1-4A53-AE60-1C84B5276713@gmail.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: hippysoyboy@gmail.com
  Subject: Re: How to avoid Trigger ping/pong / infinite loop
  In-Reply-To: <87FC4042-E7F1-4A53-AE60-1C84B5276713@gmail.com>
  References: <CAKFQuwZb+jY2A_j2MjJszBmn8YPW1imwnjefGtjR2=1NiNqdAA@mail.gmail.com> <87FC4042-E7F1-4A53-AE60-1C84B5276713@gmail.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