pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gilles Darold <gilles@darold.net>
To: 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: Wed, 6 Apr 2022 10:26:18 +0200
Message-ID: <5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net> (raw)
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>

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/

view thread (11+ messages)  latest in thread

Message-ID: <5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net>
Permalink:  ../5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net/
Also on:    postgresql.org/message-id/5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net

 · 

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: gilles@darold.net, sebastien.flaesch@4js.com, david.g.johnston@gmail.com, dgrowleyml@gmail.com
  Subject: Re: Transaction and SQL errors
  In-Reply-To: <5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net>
  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> <5bace332-011a-5846-ccea-4e0f40a4bfad@darold.net>

* 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