From e1f791f96196c06afdb478e158a9c6322b83c45d Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 30 Dec 2025 17:17:14 -0500
Subject: [PATCH v1 4/4] Remove escape_string_warning.

Previous patches removed all the functionality of this GUC.
We could keep it around as a vestigial setting, but I don't see
the point of that.  It's not like standard_conforming_strings,
which many applications set and/or test for.  Furthermore,
any application that is touching it probably needs work anyway
in the wake of disallowing standard_conforming_strings = off.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3279216.1767072538@sss.pgh.pa.us
---
 contrib/hstore/expected/hstore.out            |  1 -
 contrib/hstore/sql/hstore.sql                 |  2 --
 doc/src/sgml/config.sgml                      | 15 ---------
 src/backend/utils/misc/guc_parameters.dat     |  6 ----
 src/backend/utils/misc/guc_tables.c           |  1 -
 src/backend/utils/misc/postgresql.conf.sample |  1 -
 src/bin/pg_dump/pg_backup_archiver.c          |  2 --
 src/fe_utils/string_utils.c                   |  4 +--
 src/test/regress/expected/strings.out         | 32 -------------------
 src/test/regress/sql/strings.sql              | 19 -----------
 10 files changed, 2 insertions(+), 81 deletions(-)

diff --git a/contrib/hstore/expected/hstore.out b/contrib/hstore/expected/hstore.out
index 1836c9acf39..acea8806ba4 100644
--- a/contrib/hstore/expected/hstore.out
+++ b/contrib/hstore/expected/hstore.out
@@ -7,7 +7,6 @@ WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
 --------+---------
 (0 rows)
 
-set escape_string_warning=off;
 --hstore;
 select ''::hstore;
  hstore 
diff --git a/contrib/hstore/sql/hstore.sql b/contrib/hstore/sql/hstore.sql
index efef91292a3..8ae95e8a510 100644
--- a/contrib/hstore/sql/hstore.sql
+++ b/contrib/hstore/sql/hstore.sql
@@ -5,8 +5,6 @@ SELECT amname, opcname
 FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
 WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
 
-set escape_string_warning=off;
-
 --hstore;
 
 select ''::hstore;
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 9ca6b73aa8b..8b31a28c32b 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -11416,21 +11416,6 @@ dynamic_library_path = '/usr/local/lib/postgresql:$libdir'
       </listitem>
      </varlistentry>
 
-     <varlistentry id="guc-escape-string-warning" xreflabel="escape_string_warning">
-      <term><varname>escape_string_warning</varname> (<type>boolean</type>)
-      <indexterm><primary>strings</primary><secondary>escape warning</secondary></indexterm>
-      <indexterm>
-       <primary><varname>escape_string_warning</varname> configuration parameter</primary>
-      </indexterm>
-      </term>
-      <listitem>
-       <para>
-        This parameter no longer does anything, because
-        <varname>standard_conforming_strings</varname> cannot be turned off.
-       </para>
-      </listitem>
-     </varlistentry>
-
      <varlistentry id="guc-lo-compat-privileges" xreflabel="lo_compat_privileges">
       <term><varname>lo_compat_privileges</varname> (<type>boolean</type>)
       <indexterm>
diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils/misc/guc_parameters.dat
index 7f23186506a..2560449355a 100644
--- a/src/backend/utils/misc/guc_parameters.dat
+++ b/src/backend/utils/misc/guc_parameters.dat
@@ -991,12 +991,6 @@
   boot_val => 'true',
 },
 
-{ name => 'escape_string_warning', type => 'bool', context => 'PGC_USERSET', group => 'COMPAT_OPTIONS_PREVIOUS',
-  short_desc => 'Warn about backslash escapes in ordinary string literals.',
-  variable => 'escape_string_warning',
-  boot_val => 'true',
-},
-
 { name => 'event_source', type => 'string', context => 'PGC_POSTMASTER', group => 'LOGGING_WHERE',
   short_desc => 'Sets the application name used to identify PostgreSQL messages in the event log.',
   variable => 'event_source',
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index beea9b00657..b560ad83940 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -533,7 +533,6 @@ bool		check_function_bodies = true;
  */
 static bool default_with_oids = false;
 static bool standard_conforming_strings = true;
-static bool escape_string_warning = true;
 
 bool		current_role_is_superuser;
 
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index ec356f62ad1..c4f92fcdac8 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -847,7 +847,6 @@
 
 #array_nulls = on
 #backslash_quote = safe_encoding        # on, off, or safe_encoding
-#escape_string_warning = on
 #lo_compat_privileges = off
 #quote_all_identifiers = off
 #synchronize_seqscans = on
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 4a63f7392ae..18d3822fd82 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -3426,8 +3426,6 @@ _doSetFixedOutputState(ArchiveHandle *AH)
 
 	/* Avoid annoying notices etc */
 	ahprintf(AH, "SET client_min_messages = warning;\n");
-	if (!AH->public.std_strings)
-		ahprintf(AH, "SET escape_string_warning = off;\n");
 
 	/* Adjust row-security state */
 	if (ropt && ropt->enable_row_security)
diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c
index 130d1020d50..31fe50880f3 100644
--- a/src/fe_utils/string_utils.c
+++ b/src/fe_utils/string_utils.c
@@ -449,9 +449,9 @@ appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
 
 	/*
 	 * XXX This is a kluge to silence escape_string_warning in our utility
-	 * programs.  It should go away someday.
+	 * programs.  It can go away once pre-v19 servers are out of support.
 	 */
-	if (strchr(str, '\\') != NULL && PQserverVersion(conn) >= 80100)
+	if (strchr(str, '\\') != NULL && PQserverVersion(conn) < 190000)
 	{
 		/* ensure we are not adjacent to an identifier */
 		if (buf->len > 0 && buf->data[buf->len - 1] != ' ')
diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index 6eb92bc8442..5f2b5c39173 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -2837,38 +2837,6 @@ SELECT '\x8000000000000000'::bytea::int8 AS "-9223372036854775808",
  -9223372036854775808 | 9223372036854775807
 (1 row)
 
---
--- test behavior of escape_string_warning and standard_conforming_strings options
---
-set escape_string_warning = on;
-set standard_conforming_strings = on;
-show escape_string_warning;
- escape_string_warning 
------------------------
- on
-(1 row)
-
-show standard_conforming_strings;
- standard_conforming_strings 
------------------------------
- on
-(1 row)
-
-select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
-  f1   |   f2   |   f3    |  f4   |   f5   | f6 
--------+--------+---------+-------+--------+----
- a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
-(1 row)
-
-set escape_string_warning = off;
-set standard_conforming_strings = on;
-select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
-  f1   |   f2   |   f3    |  f4   |   f5   | f6 
--------+--------+---------+-------+--------+----
- a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
-(1 row)
-
-reset standard_conforming_strings;
 --
 -- Additional string functions
 --
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index 531d409542f..37c0893ae83 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -905,25 +905,6 @@ SELECT '\x80000000'::bytea::int4 AS "-2147483648", '\x7FFFFFFF'::bytea::int4 AS
 SELECT '\x8000000000000000'::bytea::int8 AS "-9223372036854775808",
        '\x7FFFFFFFFFFFFFFF'::bytea::int8 AS "9223372036854775807";
 
---
--- test behavior of escape_string_warning and standard_conforming_strings options
---
-set escape_string_warning = on;
-set standard_conforming_strings = on;
-
-show escape_string_warning;
-show standard_conforming_strings;
-
-select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
-
-set escape_string_warning = off;
-set standard_conforming_strings = on;
-
-select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
-
-reset standard_conforming_strings;
-
-
 --
 -- Additional string functions
 --
-- 
2.43.7

