From 449ee0b1003fed38ebd29fec6a19dec1cf12cf5e Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Tue, 18 Dec 2018 16:50:11 +0900
Subject: [PATCH 2/2] Unify psql's behavior on -c with scripts

Each -c command is equivalent to a line in a script, but they behaves
differently on failure. Fix it.
---
 src/bin/psql/startup.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index e7536a8a06..fc50301fdc 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -347,7 +347,7 @@ main(int argc, char *argv[])
 					puts(cell->val);
 
 				successResult = SendQuery(cell->val)
-					? EXIT_SUCCESS : EXIT_FAILURE;
+					? EXIT_SUCCESS : EXIT_USER;
 			}
 			else if (cell->action == ACT_SINGLE_SLASH)
 			{
@@ -368,7 +368,7 @@ main(int argc, char *argv[])
 												cond_stack,
 												NULL,
 												NULL) != PSQL_CMD_ERROR
-					? EXIT_SUCCESS : EXIT_FAILURE;
+					? EXIT_SUCCESS : EXIT_USER;
 
 				psql_scan_destroy(scan_state);
 				conditional_stack_destroy(cond_stack);
@@ -383,7 +383,11 @@ main(int argc, char *argv[])
 				Assert(false);
 			}
 
-			if (successResult != EXIT_SUCCESS && pset.on_error_stop)
+			/* EXIT_USER shuld be forgotten if ON_ERROR_STOP is not set */
+			if (successResult == EXIT_USER && !pset.on_error_stop)
+				successResult = EXIT_SUCCESS;
+
+			if (successResult != EXIT_SUCCESS)
 				break;
 		}
 
-- 
2.16.3

