Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5ja4-00ElRg-Kw for pgsql-docs@arkaria.postgresql.org; Wed, 22 Nov 2023 09:31:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r5ja2-006zaw-Ui for pgsql-docs@arkaria.postgresql.org; Wed, 22 Nov 2023 09:31:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5ja2-006zan-Lq for pgsql-docs@lists.postgresql.org; Wed, 22 Nov 2023 09:31:34 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r5jZv-007kzE-Mn for pgsql-docs@postgresql.org; Wed, 22 Nov 2023 09:31:34 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2c59a4dd14cso78403381fa.2 for ; Wed, 22 Nov 2023 01:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1700645486; x=1701250286; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=WHWtaRb2dsQ48E96zEbXluoF6FAAsxvGlJde9gsMywk=; b=P8pklSHuzzCzr2EmUy2qrlLnvL1a/sHTpfPfHd+Sk0wGZPWJI3DCuaQ+H6KLrSn1oL DOHr5jP24zae9mIQLCV+m+ZLVPl2jWgQJFe5iCTkUbpJ7Azgv3uobWIqSparnoZlnoiA LyEfWxRGlGZ1+NXtTkZOmbC8snJ9nsWk3SlzyFz03dkyjf+PQYfkvLHi/QCuqwAH7mrG FKJT2AmIl6CamxyoENUXf5BVwGkTQ/DywUAIfj3soFF1F/ou+ZhSvKktMmmdCBlzXDa4 bunPT7w4DT+hgKOk5A46HgNuU1UlFkxG7Z/UdRh9dcecDZpXyqQDZVFzoDZFyHwl6R98 TBbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700645486; x=1701250286; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WHWtaRb2dsQ48E96zEbXluoF6FAAsxvGlJde9gsMywk=; b=XcDFmBB68Bl4nhc9PPi4O3GXAbr4MQryCeiLjajecfPUHsYH/UkX+2cHiz0HLe90sW hH6gq6SS28gd7zRyIDm8rPmY77FJWyEl3dHNgbqXcAISfd4zm8F5cS5MdifostHW7HMO V2WUbS/XunaU4/fOu01dcjZs7CeVaLb9ArgVx0tpXTuO0gzpOYoV2JI5Naqo0E6f9aN7 Lf8itBQEdlDgoeiHNha+CdBVv50JDRzCFoY2+zaxQcVXjByvwHxHnBJUzcltocbCzaCn w/67mnXzck+FjPZlPtL595MPKmmUeKUbYd8kDS8o0FEO4nE549LPXxioRFLvuF7tm49M VTfA== X-Gm-Message-State: AOJu0Yw4/AJT5TsIFM9i1ZREvXWUj/Mz9Xv2N1wT8DF2p/y+FeCi/Nma Vlf3TvlXSydRERKOMLObHqo9kA== X-Google-Smtp-Source: AGHT+IHncvQjCSUqqrUVNE9gtQn6r9+0mDlrItrCEeLC9OT9HTMQ7C+Rg2OT11cJzzSPVY1oELVqLA== X-Received: by 2002:a05:651c:2045:b0:2c7:cf34:fc0c with SMTP id t5-20020a05651c204500b002c7cf34fc0cmr1025713ljo.44.1700645486459; Wed, 22 Nov 2023 01:31:26 -0800 (PST) Received: from localhost.localdomain ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id a4-20020a05600c224400b004064741f855sm1553044wmm.47.2023.11.22.01.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 01:31:26 -0800 (PST) Message-ID: Subject: Re: [DOCS] Confusing Trigger Docs. From: Laurenz Albe To: Bruce Momjian , Peter Geoghegan Cc: neil@fairwindsoft.com, PostgreSQL-documentation , Andres Freund , Heikki Linnakangas Date: Wed, 22 Nov 2023 10:31:25 +0100 In-Reply-To: References: <20170703200710.27956.64565@wrigleys.postgresql.org> <20170831132544.GC2355@momjian.us> Autocrypt: addr=laurenz.albe@cybertec.at; prefer-encrypt=mutual; keydata=mQINBGGDwAQBEADgbWy5cKXQld3N2mF+DFyiNFbi2oBl2T+XgxpPF8wTRw2D/u4bBKXP0SYSE/lA86jIVNWWU0gf1KODIkVvgJm2w4vH2VBV1b7ddVViGl1Iu+9zaRnv9wulhnH42KefepXnoean6UT1EzLM0opF/Ik0j+40TxdRtobkBprkQUyHDXWlHc2ffPs3SipyFEP9AVLf7ejRC46CXWDnsqjOBSMEW8Z4HiK/8RrPZBsKLts8dJxKF4pygOdJb0CWk8k/X1jbcfdxo+zOLjOMvJcSJ2pFdJmQHU+JufB3rePziqQ2S9Ur6sccr9XnTC1GVBWN4Lf5VHq+vf+bFJjVwg+2hrySZnAVfcOrxoqFLErr7ug1zN2nM1kcpgA4VWn4gxlJtYNYYq+9WxX5dtvnNANlG3ZCrRKQzl8lxtzoF6Zo7LUhEqPaHDwn7Rvs+IdbOn41lF5UDTJGqmC4gS/bZydW2Fy3YWm4aSaN9fgFf8D+PVkrlKAZB7gBLz1TyHjbcRf85cYF+GKKrDld5SzMB/V60VX3oP/Eo8ikFpyWaqiz1f9X7MBot3/PjJkY+wDzp3nmb19QEcOBuQiSQ4xds2r0HewbuHTAR68u8jNNMGmpm2j4x+g09Jd/WQDjqlTBZ/jEltH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TmWiSvTxvguVJ1Mb7gG4Gmh6aviDTJhfXtH4rPUNXhDLqrTH8JkJjyKROOMakIF68Hjse5vUfUxreBEOtb5r1Coa2Fe7ncJayaSE7ryrDbFqpZ 36UMAx4ulWMyqJajLNGY0DdG8qIsR5nxRhrnK/mrCidZ8F9/D3bWAl4rjtHlsztN59 +AnW5l0HsQcY9ntFL/zEBOaonjdJf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.1 (3.50.1-1.fc39) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2023-11-21 at 21:01 -0500, Bruce Momjian wrote: > On Thu, Aug 31, 2017 at 09:22:22AM -0700, Peter Geoghegan wrote: > > On Thu, Aug 31, 2017 at 6:25 AM, Bruce Momjian wrote= : > > > On Mon, Jul 3, 2017 at 08:07:10PM +0000, neil@fairwindsoft.com wrote= : > > > > The following documentation comment has been logged on the website: > > > >=20 > > > > Page: https://www.postgresql.org/docs/9.6/static/trigger-definition= .html > > > > Description: > > > >=20 > > > > https://www.postgresql.org/docs/devel/static/trigger-definition.htm= l > > > >=20 > > > > This sentence: > > > >=20 > > > > "If an INSERT contains an ON CONFLICT DO UPDATE clause, it is = possible that > > > > the effects of all row-level BEFORE INSERT triggers and all row-lev= el BEFORE > > > > UPDATE triggers can both be applied in a way that is apparent from = the final > > > > state of the updated row, if an EXCLUDED column is referenced."= ; > > > >=20 > > > > is very hard to digest. > >=20 > > EXCLUDED.* is exactly what the name suggests -- the tuple that was not > > inserted because of a conflict. So, naturally it has the effects of > > any before insert trigger, and carries them forward. But you still > > have before triggers on the update side. > >=20 > > Typically, this won't matter at all, because before triggers tend to > > be written in an idempotent fashion -- something gets filled in. But I > > can imagine cases where it is not idempotent, and apply a before > > update trigger modifies the row in a way that is surprising. Just > > because ON CONFLICT DO UPDATE was used rather than UPDATE. That's what > > the documentation warns about. >=20 > I know this thread is six years old, but I still found it confusing, so > the attached patch tries to simplify it. I agree that the paragraph you are trying to improve needs it. I am not sure about that last sentence you added: The modification of EXCLUDED columns has similar interactions. How do you modify an EXCLUDED column? Are you talking about a BEFORE INSERT trigger? Reading the original text, I get the impression that it means "the behavior is obvious if you modify a column that is used with EXCLUDED in the DO UPDATE clause, but it can also happen if that column is not user with EXCLUDED". Perhaps you should omit that sentence for clarity. Yours, Laurenz Albe