pgsql: Force standard_conforming_strings to always be ON.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Force standard_conforming_strings to always be ON.
Date: 2026-01-21 20:08:49
Message-ID: E1vieVV-001rOk-0B@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Force standard_conforming_strings to always be ON.

Continuing to support this backwards-compatibility feature has
nontrivial costs; in particular it is potentially a security hazard
if an application somehow gets confused about which setting the
server is using. We changed the default to ON fifteen years ago,
which seems like enough time for applications to have adapted.
Let's remove support for the legacy string syntax.

We should not remove the GUC altogether, since client-side code will
still test it, pg_dump scripts will attempt to set it to ON, etc.
Instead, just prevent it from being set to OFF. There is precedent
for this approach (see commit de66987ad).

This patch does remove the related GUC escape_string_warning, however.
That setting does nothing when standard_conforming_strings is on,
so it's now useless. We could leave it in place as a do-nothing
setting to avoid breaking clients that still set it, if there are any.
But it seems likely that any such client is also trying to turn off
standard_conforming_strings, so it'll need work anyway.

The client-side changes in this patch are pretty minimal, because even
though we are dropping the server's support, most of our clients still
need to be able to talk to older server versions. We could remove
dead client code only once we disclaim compatibility with pre-v19
servers, which is surely years away. One change of note is that
pg_dump/pg_dumpall now set standard_conforming_strings = on in their
source session, rather than accepting the source server's default.
This ensures that literals in view definitions and such will be
printed in a way that's acceptable to v19+. In particular,
pg_upgrade will work transparently even if the source installation has
standard_conforming_strings = off. (However, pg_restore will behave
the same as before if given an archive file containing
standard_conforming_strings = off. Such an archive will not be safely
restorable into v19+, but we shouldn't break the ability to extract
valid data from it for use with an older server.)

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/3279216.1767072538@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/45762084545ec14dbbe66ace1d69d7e89f8978ac

Modified Files
--------------
contrib/hstore/expected/hstore.out | 1 -
contrib/hstore/sql/hstore.sql | 2 -
contrib/pg_stat_statements/pg_stat_statements.c | 3 -
contrib/pg_trgm/expected/pg_trgm.out | 3 -
contrib/pg_trgm/sql/pg_trgm.sql | 4 -
contrib/test_decoding/test_decoding.c | 4 +-
doc/src/sgml/config.sgml | 51 ++-------
doc/src/sgml/ecpg.sgml | 4 +-
doc/src/sgml/func/func-matching.sgml | 16 ---
doc/src/sgml/hstore.sgml | 4 +-
doc/src/sgml/libpq.sgml | 18 +--
doc/src/sgml/protocol.sgml | 3 +-
doc/src/sgml/syntax.sgml | 35 ------
src/backend/commands/variable.c | 15 +++
src/backend/parser/scan.l | 76 +------------
src/backend/utils/adt/quote.c | 8 +-
src/backend/utils/adt/ruleutils.c | 6 +-
src/backend/utils/misc/guc_parameters.dat | 14 +--
src/backend/utils/misc/guc_tables.c | 4 +-
src/backend/utils/misc/postgresql.conf.sample | 2 -
src/bin/pg_dump/pg_backup_archiver.c | 2 -
src/bin/pg_dump/pg_dump.c | 23 +++-
src/bin/pg_dump/pg_dumpall.c | 20 ++--
src/fe_utils/string_utils.c | 4 +-
src/include/parser/parser.h | 4 +-
src/include/parser/scanner.h | 5 +-
src/include/utils/guc_hooks.h | 2 +
src/interfaces/ecpg/test/expected/sql-quote.c | 90 ++++-----------
src/interfaces/ecpg/test/expected/sql-quote.stderr | 107 +++++------------
src/interfaces/ecpg/test/expected/sql-quote.stdout | 3 -
src/interfaces/ecpg/test/expected/sql-show.c | 2 +-
src/interfaces/ecpg/test/expected/sql-show.stderr | 4 +-
src/interfaces/ecpg/test/expected/sql-show.stdout | 2 +-
src/interfaces/ecpg/test/sql/quote.pgc | 10 --
src/interfaces/ecpg/test/sql/show.pgc | 2 +-
src/test/examples/testlibpq3.c | 1 -
src/test/examples/testlibpq3.sql | 1 -
.../modules/test_regex/expected/test_regex.out | 1 -
.../test_regex/expected/test_regex_utf8.out | 1 -
src/test/modules/test_regex/sql/test_regex.sql | 2 -
.../modules/test_regex/sql/test_regex_utf8.sql | 2 -
src/test/regress/expected/plpgsql.out | 45 --------
src/test/regress/expected/regex.out | 2 -
src/test/regress/expected/strings.out | 126 +--------------------
src/test/regress/sql/plpgsql.sql | 22 ----
src/test/regress/sql/regex.sql | 3 -
src/test/regress/sql/strings.sql | 50 +-------
src/tutorial/syscat.source | 7 +-
48 files changed, 155 insertions(+), 661 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2026-01-21 20:21:28 pgsql: Refactor some SIMD and popcount macros.
Previous Message Álvaro Herrera 2026-01-21 19:07:57 pgsql: Allow Boolean reloptions to have ternary values