Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egwmc-0008S2-7P for pgsql-general@arkaria.postgresql.org; Wed, 31 Jan 2018 18:06:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egwmZ-0008JR-Gw for pgsql-general@arkaria.postgresql.org; Wed, 31 Jan 2018 18:06:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1egwmZ-0008JI-9e for pgsql-general@lists.postgresql.org; Wed, 31 Jan 2018 18:06:51 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egwmQ-0004qJ-Ur for pgsql-general@lists.postgresql.org; Wed, 31 Jan 2018 18:06:50 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 7E64317E3; Wed, 31 Jan 2018 19:06:40 +0100 (CET) Date: Wed, 31 Jan 2018 19:06:40 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Information on savepoint requirement within transctions Message-ID: <20180131180640.k56anmhgnfxy3oin@hjp.at> References: <5A6B3F78.6030908@sibvisions.com> <5A6B4A12.9000002@sibvisions.com> <5A6EDD41.70005@sibvisions.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3wga7u37qzy6sk4i" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --3wga7u37qzy6sk4i Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-01-29 06:36:41 -0700, David G. Johnston wrote: > On Mon, Jan 29, 2018 at 1:37 AM, Robert Zenz > wrote: >=20 > Documentation, bug report, mailing list discussions, > something like that. In particular I'm interested in the questions: >=20 > =C2=A0* Why are they required in combination with failing statements = (when every > other database does an "automatic savepoint and rollback" for a failed > statement)? > =C2=A0* When was that behavior chosen? Was it always like that? Was i= t adopted > later? > =C2=A0* What is the design decision behind it? >=20 > There is a lot of information on what savepoints are and how they wor= k (and > also > thanks to you I'm now fairly certain I have good grasp on them), but = I fail > to > locate documentation on these questions. >=20 >=20 > =E2=80=8BThose questions would not be answered in user-facing documentati= on. I think the first (and possibly last) question should be answered in user-facing documentation. To understand something I don't just need to know how something works, but also why it works that way. This is especially the case if the behaviour differs from similar systems. I think the reason for the behaviour of Oracle, MySQL, etc. is that a an error in an SQL statement is not necessarily an error in business logic. One might reasonably write code like this: begin transaction ... insert into foo ... if error =3D=3D unique_key_violation: select id from foo where ... update foo where id=3D... ... commit; Indeed I'm quite sure that I have written something like this several times. I have also tested tables or columns for existence simply by selecting from them.=20 The reason for the PostgreSQL behaviour is probably because it is safer: If it's the programmer's responsibility to test for the failure of individual SQL statements, it is quite likely that the programmer forgets a check and commits inconsistent data. This can't happen with the PostgreSQL model. If the programmer wants to tolerate and error, they have to handle it explicitely (with a savepoint or even a full transaction). I can't really think of a reason why the MSSQL behaviour might be useful, but I'm sure that they had a use-case in mind when they designed this. hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --3wga7u37qzy6sk4i Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlpyBasACgkQ8g5IURL+ KF1LEA//d5jjYxvcfWTOIt31cA8ZqwaNCdWOZGkwxWw57FxhDrelXSX4vKxryFOi dq5ULghMG2AZ2PA4itO16DntQyzzzwBavMh7VVZh55NJ2tB0Ou5DvEbHS4DpE1gv ij7BqL4KlnvJXRTU7jc59Vng7Bz2U0g2wlbVu3xhjK1VVZQev0MEYzbxHb/5UhH7 AJs72dkxVa6gEKXYchu6q6q1y6LS8ldQAgqQ4CUsvlEMe6rKB6ROZS8t16+a9EHe lLOFQBszXDnA+OaqiHyd9ASN6LDKYDnlmDNQRCzADg1VU1aa3pjv50S6FvMYbpz1 v3UAqMYrDCHimvYBmsXLTMFGEqIGYHyPvR9jE2RdCjJQz2WpMmcVzHQ34lBvtDXn 1ARfrFmVHKVfzPVYQArwtmHOBMObPh7QgitZrm4MIlOnU/ECFuObhuaVbC+O1b0Y jDBWbiQZDOuNoXJRmEMEsIWSoS3Fhbi9fJQZJTzw7BlGPiefUIyB8DUKe+nnH2ks avNKytSzFTg/PbDtQvJuecrgRVd8jtt1EbeDoNGCG/Qt52GuyppVrJU0s0C7I/9O 6I0qv46Hp6PoQZOGYVz3yub0+iFGVyXSQN7OVT68PtP+eZ5W3M5OF2ssaYttNXIf KLF8a0Y/PnPCxgb/SUQZE2QkFaGZ5EjeUthrmBpk4gbM0xGJ394= =1sM+ -----END PGP SIGNATURE----- --3wga7u37qzy6sk4i--