0001-change-commit-semantics-to-throw-an-error-and-then-r.patch

application/octet-stream

Filename: 0001-change-commit-semantics-to-throw-an-error-and-then-r.patch
Type: application/octet-stream
Part: 0
Message: Re: Error on failed COMMIT

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0001
Subject: change commit semantics to throw an error and then rollback instead of silently rolling back
File+
src/backend/tcop/postgres.c 11 4
src/backend/utils/error/elog.c 3 0
src/include/utils/elog.h 6 4
From 1d82fed9672b8de115e679bc6b4d4d4a52c34f8f Mon Sep 17 00:00:00 2001
From: Dave Cramer <davecramer@gmail.com>
Date: Wed, 26 Feb 2020 15:38:18 -0500
Subject: [PATCH] change commit semantics to throw an error and then rollback
 instead of silently rolling back

---
 src/backend/tcop/postgres.c    | 15 +++++++++++----
 src/backend/utils/error/elog.c |  3 +++
 src/include/utils/elog.h       | 10 ++++++----
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 0a6f80963b..53fa507d7d 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -1093,14 +1093,21 @@ exec_simple_query(const char *query_string)
 		 * might be safe to allow some additional utility commands in this
 		 * state, but not many...)
 		 */
-		if (IsAbortedTransactionBlockState() &&
-			!IsTransactionExitStmt(parsetree->stmt))
-			ereport(ERROR,
+		if (IsAbortedTransactionBlockState()) {
+			if (!IsTransactionExitStmt(parsetree->stmt))
+				ereport(ERROR,
 					(errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
 					 errmsg("current transaction is aborted, "
 							"commands ignored until end of transaction block"),
 					 errdetail_abort()));
-
+			else {
+				ereport(USER_ERROR,
+					(errcode(ERRCODE_IN_FAILED_SQL_TRANSACTION),
+					 errmsg("current transaction failed, "
+							"rolling back"),
+					 errdetail_abort()));
+			}
+		}
 		/* Make sure we are in a transaction command */
 		start_xact_command();
 
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index f5b0211f66..20cfcfa61d 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -3460,6 +3460,9 @@ error_severity(int elevel)
 		case WARNING:
 			prefix = gettext_noop("WARNING");
 			break;
+		case USER_ERROR:
+			prefix = gettext_noop("USER_ERROR");
+			break;
 		case ERROR:
 			prefix = gettext_noop("ERROR");
 			break;
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index 0a4ef029ce..8f5cfc4b33 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -40,17 +40,19 @@
 #define WARNING		19			/* Warnings.  NOTICE is for expected messages
 								 * like implicit sequence creation by SERIAL.
 								 * WARNING is for unexpected messages. */
-#define ERROR		20			/* user error - abort transaction; return to
+#define USER_ERROR	20	    	/* user error - abort transaction; return to
 								 * known state */
+#define ERROR		21
+
 /* Save ERROR value in PGERROR so it can be restored when Win32 includes
  * modify it.  We have to use a constant rather than ERROR because macros
  * are expanded only when referenced outside macros.
  */
 #ifdef WIN32
-#define PGERROR		20
+#define PGERROR		21
 #endif
-#define FATAL		21			/* fatal error - abort process */
-#define PANIC		22			/* take down the other backends with me */
+#define FATAL		22			/* fatal error - abort process */
+#define PANIC		23			/* take down the other backends with me */
 
  /* #define DEBUG DEBUG1 */	/* Backward compatibility with pre-7.3 */
 
-- 
2.20.1 (Apple Git-117)