From ff2164dd77fde04b961f4bbbc9a1e4d9830733ff Mon Sep 17 00:00:00 2001
From: Andrew Dunstan <andrew@dunslane.net>
Date: Wed, 30 Nov 2022 11:32:30 -0500
Subject: [PATCH 3/5] Add safe error handling to bool_in

---
 src/backend/utils/adt/bool.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c
index cd7335287f..d4ca519c9b 100644
--- a/src/backend/utils/adt/bool.c
+++ b/src/backend/utils/adt/bool.c
@@ -18,6 +18,8 @@
 #include <ctype.h>
 
 #include "libpq/pqformat.h"
+#include "nodes/nodes.h"
+#include "nodes/primnodes.h"
 #include "utils/builtins.h"
 
 /*
@@ -148,6 +150,16 @@ boolin(PG_FUNCTION_ARGS)
 	if (parse_bool_with_len(str, len, &result))
 		PG_RETURN_BOOL(result);
 
+	if (fcinfo->context && IsA(fcinfo->context, IOCallContext))
+	{
+		IOCallContext *ioc = (IOCallContext *) fcinfo->context;
+		if (ioc->no_error_throw)
+		{
+			ioc->error_found = true;
+			PG_RETURN_BOOL(false);
+		}
+	}
+
 	ereport(ERROR,
 			(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
 			 errmsg("invalid input syntax for type %s: \"%s\"",
-- 
2.34.1

