From 113d42772be2c2abd71fd142cde9240522f143d7 Mon Sep 17 00:00:00 2001
From: Mark Dilger <hornschnorter@gmail.com>
Date: Thu, 7 Nov 2019 07:51:06 -0800
Subject: [PATCH v1 1/5] Deprecating unused SPI error codes.

The SPI_ERROR_NOOUTFUNC and SPI_ERROR_CONNECT codes, defined in spi.h,
were no longer used anywhere in the sources except nominally in spi.c
where SPI_result_code_string(int code) was translating them to a cstring
for use in error messages.  But since the system never returns these
error codes, it seems unlikely anybody still needs to be able to convert
them to a string.

Removing these from spi.c, from the docs, and from a code comment in
contrib.  Leaving the definition in spi.h for backwards compatibility of
third-party applications.
---
 contrib/spi/refint.c       |  2 +-
 doc/src/sgml/spi.sgml      | 14 ++------------
 src/backend/executor/spi.c |  4 ----
 src/include/executor/spi.h |  4 ++--
 4 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/contrib/spi/refint.c b/contrib/spi/refint.c
index adf0490f85..00253a63e9 100644
--- a/contrib/spi/refint.c
+++ b/contrib/spi/refint.c
@@ -392,7 +392,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
 			char	   *oldval = SPI_getvalue(trigtuple, tupdesc, fnumber);
 			char	   *newval;
 
-			/* this shouldn't happen! SPI_ERROR_NOOUTFUNC ? */
+			/* this shouldn't happen! */
 			if (oldval == NULL)
 				/* internal error */
 				elog(ERROR, "check_foreign_key: SPI_getvalue returned %s", SPI_result_code_string(SPI_result));
diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml
index 9e37fc3a14..d1e6582d96 100644
--- a/doc/src/sgml/spi.sgml
+++ b/doc/src/sgml/spi.sgml
@@ -128,14 +128,6 @@ int SPI_connect_ext(int <parameter>options</parameter>)
     </listitem>
    </varlistentry>
 
-   <varlistentry>
-    <term><symbol>SPI_ERROR_CONNECT</symbol></term>
-    <listitem>
-     <para>
-      on error
-     </para>
-    </listitem>
-   </varlistentry>
   </variablelist>
  </refsect1>
 </refentry>
@@ -3231,12 +3223,10 @@ char * SPI_getvalue(HeapTuple <parameter>row</parameter>, TupleDesc <parameter>r
   <title>Return Value</title>
 
   <para>
-   Column value, or <symbol>NULL</symbol> if the column is null,
+   Column value, or <symbol>NULL</symbol> if the column is null, or
    <parameter>colnumber</parameter> is out of range
    (<varname>SPI_result</varname> is set to
-   <symbol>SPI_ERROR_NOATTRIBUTE</symbol>), or no output function is
-   available (<varname>SPI_result</varname> is set to
-   <symbol>SPI_ERROR_NOOUTFUNC</symbol>).
+   <symbol>SPI_ERROR_NOATTRIBUTE</symbol>).
   </para>
  </refsect1>
 </refentry>
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 2c0ae395ba..2bb49e6919 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -1708,8 +1708,6 @@ SPI_result_code_string(int code)
 
 	switch (code)
 	{
-		case SPI_ERROR_CONNECT:
-			return "SPI_ERROR_CONNECT";
 		case SPI_ERROR_COPY:
 			return "SPI_ERROR_COPY";
 		case SPI_ERROR_OPUNKNOWN:
@@ -1724,8 +1722,6 @@ SPI_result_code_string(int code)
 			return "SPI_ERROR_TRANSACTION";
 		case SPI_ERROR_NOATTRIBUTE:
 			return "SPI_ERROR_NOATTRIBUTE";
-		case SPI_ERROR_NOOUTFUNC:
-			return "SPI_ERROR_NOOUTFUNC";
 		case SPI_ERROR_TYPUNKNOWN:
 			return "SPI_ERROR_TYPUNKNOWN";
 		case SPI_ERROR_REL_DUPLICATE:
diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h
index ad69a5ce43..a2ea6dda5f 100644
--- a/src/include/executor/spi.h
+++ b/src/include/executor/spi.h
@@ -36,7 +36,7 @@ typedef struct SPITupleTable
 /* Plans are opaque structs for standard users of SPI */
 typedef struct _SPI_plan *SPIPlanPtr;
 
-#define SPI_ERROR_CONNECT		(-1)
+#define SPI_ERROR_CONNECT		(-1)	/* not used anymore */
 #define SPI_ERROR_COPY			(-2)
 #define SPI_ERROR_OPUNKNOWN		(-3)
 #define SPI_ERROR_UNCONNECTED	(-4)
@@ -45,7 +45,7 @@ typedef struct _SPI_plan *SPIPlanPtr;
 #define SPI_ERROR_PARAM			(-7)
 #define SPI_ERROR_TRANSACTION	(-8)
 #define SPI_ERROR_NOATTRIBUTE	(-9)
-#define SPI_ERROR_NOOUTFUNC		(-10)
+#define SPI_ERROR_NOOUTFUNC		(-10)	/* not used anymore */
 #define SPI_ERROR_TYPUNKNOWN	(-11)
 #define SPI_ERROR_REL_DUPLICATE (-12)
 #define SPI_ERROR_REL_NOT_FOUND (-13)

base-commit: effa40281bb1f6c71e81c980f86852ab3be603c3
-- 
2.20.1

