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 1nc0zt-0002C8-3X for pgsql-general@arkaria.postgresql.org; Wed, 06 Apr 2022 08:26:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nc0zo-0000ws-4B for pgsql-general@arkaria.postgresql.org; Wed, 06 Apr 2022 08:26:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nc0zn-0000wj-LL for pgsql-general@lists.postgresql.org; Wed, 06 Apr 2022 08:26:31 +0000 Received: from 4.mo561.mail-out.ovh.net ([178.33.46.10]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nc0zk-0001Bl-Ee for pgsql-general@postgresql.org; Wed, 06 Apr 2022 08:26:30 +0000 Received: from player157.ha.ovh.net (unknown [10.109.143.189]) by mo561.mail-out.ovh.net (Postfix) with ESMTP id 851DF247E6 for ; Wed, 6 Apr 2022 08:26:24 +0000 (UTC) Received: from darold.net (lfbn-lyo-1-666-165.w90-119.abo.wanadoo.fr [90.119.236.165]) (Authenticated sender: gilles@darold.net) by player157.ha.ovh.net (Postfix) with ESMTPSA id 66F6A293315EB; Wed, 6 Apr 2022 08:26:19 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-100R00325d2c53d-1bcb-4ca4-9374-bfbebe0b1967, 32AC5DA18F5AD3FFB0863CE2710A0DCD75487C11) smtp.auth=gilles@darold.net X-OVh-ClientIp: 90.119.236.165 Content-Type: multipart/alternative; boundary="------------4KH08dqvprmjvtMA0DkYB0YP" Message-ID: <5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net> Date: Wed, 6 Apr 2022 10:26:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Sebastien Flaesch , "David G. Johnston" Cc: David Rowley , "pgsql-general@postgresql.org" References: From: Gilles Darold Subject: Re: Transaction and SQL errors In-Reply-To: X-Ovh-Tracer-Id: 5670031932542656188 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvvddrudejiedgtdegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurheptgfkffggfgfvfhfhufgjsegrtderredtfeejnecuhfhrohhmpefiihhllhgvshcuffgrrhholhguuceoghhilhhlvghssegurghrohhlugdrnhgvtheqnecuggftrfgrthhtvghrnhepledthffffeevgeeugfelhfeugfffuedtfeeghefffffhteduudekueduffdtffdvnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghdpuggrrhholhgurdhnvghtnecukfhppedtrddtrddtrddtpdeltddrudduledrvdefiedrudeiheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepphhlrgihvghrudehjedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgihhllhgvshesuggrrhholhgurdhnvghtpdhnsggprhgtphhtthhopedupdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlhesphhoshhtghhrvghsqhhlrdhorhhg List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------4KH08dqvprmjvtMA0DkYB0YP Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 04/04/2022 à 18:20, Sebastien Flaesch a écrit : > David, > > Personally, I can see where it has significant value for psql in > interactive mode because people make typos.  Application code > doesn't.  That removes a whole class of problems where the feature > provides benefit. > > > Sure, application code must not have typos, but I prefer to let the DB > engine check for SQL constraints. > > Imagine the following case: > > BEGIN WORK > ... (some other SQL) ... > DELETE FROM items WHERE item_id = 12823  -- Can raise foreign key > error if sql-error then > ... > > To me it's better than: > > BEGIN WORK > ... > SELECT ... FROM orders WHERE item_id = 12823 > if not-found then -- make sure we get no SQL error than cancels TX! >   DELETE FROM items WHERE item_id = 12823 > endif > ... > > ... and not even sure it's valid atomic code depending on isolation > level... > > A good argument for PostgreSQL's behavior would be that it's better to > cancel the whole transaction and restart all SQL commands. > > However, legacy code is often spaghetti code where one function starts > the TX, then calls other functions doing SQL ... ( yes, good candidate > for savepoints usage! ) > > Anyway, thanks for the info, nothing planed short term, and that's > what I was asking for. > > Cheers! > Seb FYI there was a discussion [1] and a patch to allow this feature through an extension because having this implemented in core will probably never happen. Everything was ready but the final status is Rejected so I don't think you might expect any planned work on this feature in any term. But who knows, things can evolve. [1] https://www.postgresql.org/message-id/983d80b3-d187-127a-2de5-38c92ccb38ab%40darold.net -- Gilles Darold http://www.darold.net/ --------------4KH08dqvprmjvtMA0DkYB0YP Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Le 04/04/2022 à 18:20, Sebastien Flaesch a écrit :
David,

Personally, I can see where it has significant value for psql in interactive mode because people make typos.  Application code doesn't.  That removes a whole class of problems where the feature provides benefit.


Sure, application code must not have typos, but I prefer to let the DB engine check for SQL constraints.

Imagine the following case:

BEGIN WORK
... (some other SQL) ...
DELETE FROM items WHERE item_id = 12823  -- Can raise foreign key error if sql-error then
...

To me it's better than:

BEGIN WORK
...
SELECT ... FROM orders WHERE item_id = 12823  
if not-found then -- make sure we get no SQL error than cancels TX!
  DELETE FROM items WHERE item_id = 12823
endif
...

... and not even sure it's valid atomic code depending on isolation level...

A good argument for PostgreSQL's behavior would be that it's better to cancel the whole transaction and restart all SQL commands.

However, legacy code is often spaghetti code where one function starts the TX, then calls other functions doing SQL ... ( yes, good candidate for savepoints usage! )

Anyway, thanks for the info, nothing planed short term, and that's what I was asking for.

Cheers!
Seb


FYI there was a discussion [1] and a patch to allow this feature through an extension because having this implemented in core will probably never happen. Everything was ready but the final status is Rejected so I don't think you might expect any planned work on this feature in any term. But who knows, things can evolve.


[1] https://www.postgresql.org/message-id/983d80b3-d187-127a-2de5-38c92ccb38ab%40darold.net 

-- 
Gilles Darold
http://www.darold.net/
--------------4KH08dqvprmjvtMA0DkYB0YP--