Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfVDk-0006SW-Kl for pgsql-general@arkaria.postgresql.org; Tue, 26 Oct 2021 22:47:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfVDj-0007kN-Ji for pgsql-general@arkaria.postgresql.org; Tue, 26 Oct 2021 22:47:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfVDi-0007kD-T5 for pgsql-general@lists.postgresql.org; Tue, 26 Oct 2021 22:47:03 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mfVDe-0003yf-Tx for pgsql-general@postgresql.org; Tue, 26 Oct 2021 22:47:02 +0000 Received: by mail-pf1-x42e.google.com with SMTP id f11so827476pfc.12 for ; Tue, 26 Oct 2021 15:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mcG7TUWCEXfOvo80Bi0KBjxJRRIDxVJ0K1swfVeBe3U=; b=k8+leqnEFt1Un02vO71g0/UEDPqt78M4vdZIWqnb+Tq5o40JWcSN4IxK7UKvtwOURp MS5Nq3W2tfgI5owug/wQzE93hJOVM6cYwiT0SjiAa8HZ3QaGQDJbmKoqkGZVMJwoDq5p yWaJ22iF7BPDVdhEId6CRiLBZYuRANLFxyGSOx9vUV810QrICO3v6eUPQ208Koc27fQ6 lgs3ceqBjlBXnmBohRu51jbUjT4F26TQwHOZ02HWczQNRFDZreWmwpZBqrbVsuBGr28h 921SYvIsfWefdBu4ZFAY6T373n2kiTz/4lI85MSWIO+41T3xlobTHaG0f/V0iuSb7ycC yvEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mcG7TUWCEXfOvo80Bi0KBjxJRRIDxVJ0K1swfVeBe3U=; b=4PYoKLKT7v5yMxGJlBOx1Kw+x3IQponKV59gccVlZDun5bo8xjouwnmgR2iDuyKUlS 673V/AjsaErxM9E72/uXzlaK3uDSWNtgfQY2DkO4yCVzikccWneTkWVEgVmho29L2+TJ Eyfmjm+w/9fB1eGVKcvV4b3uo1nsKC85K6WbxbY9yJYYIix5Gs+MVdqLOvrFWJYRI4+m cAla7t8a+TzKsZZnG0wveVP/M4xBNQGNDsXYB0H1U2N/86OCBjHr5sf1+0QRbtOQxDTO zyxg6B/4zfHXiKSR1OtspYQ3OABA9pVcz5Q9MYfM/uEHRfN5PTuVsnFEDd90Ri16MSJk 0zAQ== X-Gm-Message-State: AOAM533vS/5pKlkY64E42+xNu5bpXA6bW0dxYnvv0xvP2VUlKHidVo5V 7MYDlAz8S03kQmZR6b78Ah1DMpB/HTK6ZHRf6wBMBUZjXEE860e/116a/VPo3dnGxohaBYLrJdm VHfMvBQAOcAYmd/I5Y2BZrUw83GXfnzGTtaO3IYjsahn5o0sJMI6gCbEIalq7EU4U0Gn6WwvNVt aKQATa5yEbEfm7nbsFUCQlmK+vggYTWpHtH1Vc X-Google-Smtp-Source: ABdhPJzsHYFKULGfkssAJZdxRad6nTrRYhKO/leZpYldQykYKsX6OfntdR//cPy1Kf6ih/JZtoAMTA== X-Received: by 2002:a63:7502:: with SMTP id q2mr21664819pgc.54.1635288416371; Tue, 26 Oct 2021 15:46:56 -0700 (PDT) Received: from laptop280-ma-us.hitronhub.home (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id b14sm1783459pjo.44.2021.10.26.15.46.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Oct 2021 15:46:55 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Determining if a table really changed in a trigger From: Mark Dilger In-Reply-To: Date: Tue, 26 Oct 2021 15:46:54 -0700 Cc: Postgres General Content-Transfer-Encoding: quoted-printable Message-Id: <6526D693-D520-4B94-B44F-4A2770FBF778@enterprisedb.com> References: To: Mitar X-Mailer: Apple Mail (2.3608.120.23.2.7) X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Oct 26, 2021, at 3:39 PM, Mitar wrote: >=20 > On Tue, Oct 26, 2021 at 10:55 PM Mark Dilger > wrote: >> Note that there is a performance cost to storing the old rows using = the REFERENCING clause of the trigger >=20 > Yea, by moving the trivial update check to a rule, I need REFERENCING > only to see if there were any changes at all. This seems a bit > excessive. Is there a way to check if any rows have been affected by > an UPDATE inside a per statement trigger without using REFERENCING? I felt the same way about it, but after glancing quickly through the = code and docs nothing jumped out. The information is clearly available, = as it gets returned at the end of the UPDATE statement in the "UPDATE 0" = OR "UPDATE 3", but I don't see how to access that from the trigger. I = might have to submit a patch for that if nobody else knows a way to get = it. (Hopefully somebody will respond with the answer...?) > I also notice that you check if a table has any rows with: >=20 > SELECT true INTO have_rows FROM old_values LIMIT 1; > IF have_rows THEN ... >=20 > Is this just a question of style or is this a better approach than my: >=20 > PERFORM * FROM old_values LIMIT 1; > IF FOUND THEN ... There is no reason to prefer my spelling of that over yours. I didn't = put much thought into it, but rather just wrote it the first way that = occurred to me. =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company