From: Sebastien Flaesch <sebastien.flaesch@4js.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Transaction and SQL errors
Date: Mon, 4 Apr 2022 16:20:26 +0000
Message-ID: <DBAP191MB1289EB2F6BDA9A03B02C03DAB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAKFQuwZaMwHsQ3Ev5wcfXfBgb+H-DQmJcTGztHy+t6TOriu48Q@mail.gmail.com>
References: <DBAP191MB1289450C733A5A3662C2257EB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
<CAApHDvpz8HohzRpPq3OPkyS3=wV2aQPmE72O3i5D5RbVXehSzA@mail.gmail.com>
<DBAP191MB128948A1A03136C661483EBAB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
<CAKFQuwZaMwHsQ3Ev5wcfXfBgb+H-DQmJcTGztHy+t6TOriu48Q@mail.gmail.com>
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
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: sebastien.flaesch@4js.com, david.g.johnston@gmail.com, dgrowleyml@gmail.com
Subject: Re: Transaction and SQL errors
In-Reply-To: <DBAP191MB1289EB2F6BDA9A03B02C03DAB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
References: <DBAP191MB1289450C733A5A3662C2257EB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> <CAApHDvpz8HohzRpPq3OPkyS3=wV2aQPmE72O3i5D5RbVXehSzA@mail.gmail.com> <DBAP191MB128948A1A03136C661483EBAB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> <CAKFQuwZaMwHsQ3Ev5wcfXfBgb+H-DQmJcTGztHy+t6TOriu48Q@mail.gmail.com> <DBAP191MB1289EB2F6BDA9A03B02C03DAB0E59@DBAP191MB1289.EURP191.PROD.OUTLOOK.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