public inbox for [email protected]
help / color / mirror / Atom feed[PATCH] Add regression test for mismatched ENCODING and LOCALE in CREATE DATABASE
2+ messages / 2 participants
[nested] [flat]
* [PATCH] Add regression test for mismatched ENCODING and LOCALE in CREATE DATABASE
@ 2026-05-23 12:10 Yushu Chen <[email protected]>
2026-05-25 18:42 ` Re: [PATCH] Add regression test for mismatched ENCODING and LOCALE in CREATE DATABASE Tom Lane <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Yushu Chen @ 2026-05-23 12:10 UTC (permalink / raw)
To: pgsql-hackers
Hi,
While reading the CREATE DATABASE documentation at
https://www.postgresql.org/docs/current/sql-createdatabase.html, I
noticed the following sentence:
"The specified locale and encoding settings must match, or an error
will be reported."
However, we do not currently have regression coverage for that failure case.
This patch adds a regression test covering incompatible ENCODING and
LOCALE combinations, for example:
CREATE DATABASE dbtest
LOCALE 'en_US.UTF-8'
ENCODING LATIN1
TEMPLATE template0;
Which is expected to fail due to the encoding/locale mismatch.
The patch only adds test coverage and does not change backend behavior.
Regards,
Yushu
Attachments:
[application/octet-stream] v1-0001-regress-test-create-database-with-locale-encoding.patch (2.2K, 2-v1-0001-regress-test-create-database-with-locale-encoding.patch)
download | inline diff:
From b454a1ab5867b308f9bd138c3db687f0014f849b Mon Sep 17 00:00:00 2001
From: Yushu Chen <[email protected]>
Date: Sat, 23 May 2026 20:02:03 +0800
Subject: [PATCH v1] regress test create database with locale encoding mismatch
src/test/regress/sql/database.sql does not have regression coverage
for the failure case described in the documentation
https://www.postgresql.org/docs/current/sql-createdatabase.html
"The specified locale and encoding settings must match,
or an error will be reported."
Author: Yushu Chen <[email protected]>
---
src/test/regress/expected/database.out | 5 +++++
src/test/regress/sql/database.sql | 3 +++
2 files changed, 8 insertions(+)
diff --git a/src/test/regress/expected/database.out b/src/test/regress/expected/database.out
index 6b879b0f62a..50089ff46e1 100644
--- a/src/test/regress/expected/database.out
+++ b/src/test/regress/expected/database.out
@@ -4,6 +4,11 @@ ALTER DATABASE regression_tbd RENAME TO regression_utf8;
ALTER DATABASE regression_utf8 SET TABLESPACE regress_tblspace;
ALTER DATABASE regression_utf8 SET TABLESPACE pg_default;
ALTER DATABASE regression_utf8 CONNECTION_LIMIT 123;
+-- Test raises an error when locale and encoding mismatch.
+CREATE DATABASE regression_locale_encoding_not_match
+ LOCALE "en_US.UTF-8" ENCODING LATIN9 TEMPLATE template0;
+ERROR: encoding "LATIN9" does not match locale "en_US.UTF-8"
+DETAIL: The chosen LC_CTYPE setting requires encoding "UTF8".
-- Test PgDatabaseToastTable. Doing this with GRANT would be slow.
BEGIN;
UPDATE pg_database
diff --git a/src/test/regress/sql/database.sql b/src/test/regress/sql/database.sql
index 4ef36127291..95063c851ac 100644
--- a/src/test/regress/sql/database.sql
+++ b/src/test/regress/sql/database.sql
@@ -4,6 +4,9 @@ ALTER DATABASE regression_tbd RENAME TO regression_utf8;
ALTER DATABASE regression_utf8 SET TABLESPACE regress_tblspace;
ALTER DATABASE regression_utf8 SET TABLESPACE pg_default;
ALTER DATABASE regression_utf8 CONNECTION_LIMIT 123;
+-- Test raises an error when locale and encoding mismatch.
+CREATE DATABASE regression_locale_encoding_not_match
+ LOCALE "en_US.UTF-8" ENCODING LATIN9 TEMPLATE template0;
-- Test PgDatabaseToastTable. Doing this with GRANT would be slow.
BEGIN;
--
2.50.1 (Apple Git-155)
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [PATCH] Add regression test for mismatched ENCODING and LOCALE in CREATE DATABASE
2026-05-23 12:10 [PATCH] Add regression test for mismatched ENCODING and LOCALE in CREATE DATABASE Yushu Chen <[email protected]>
@ 2026-05-25 18:42 ` Tom Lane <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2026-05-25 18:42 UTC (permalink / raw)
To: Yushu Chen <[email protected]>; +Cc: pgsql-hackers
Yushu Chen <[email protected]> writes:
> While reading the CREATE DATABASE documentation at
> https://www.postgresql.org/docs/current/sql-createdatabase.html, I
> noticed the following sentence:
> "The specified locale and encoding settings must match, or an error
> will be reported."
> However, we do not currently have regression coverage for that failure case.
The reason there is no test for that is that the spelling of locale
names, and indeed the presence of any particular locale, is variable
across platforms. Your proposed test case might work fine on your
machine, but it will fail on a nontrivial fraction of our buildfarm
(where "fail" means "produce some other error message than what the
test is expecting").
As a recent example where I too was overoptimistic about this,
see the sad history of my attempts to install coverage of NLS
translation (8c498479d, 5b275a6e1, fe7ede45f, 7db6809ce,
84a3778c7, 462e24765).
We could perhaps install the test with multiple variant files to
accept the cases we see in practice. But that would be a pain
in the rear for maintenance, and you have to wonder what it'd
actually be proving.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-05-25 18:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-05-23 12:10 [PATCH] Add regression test for mismatched ENCODING and LOCALE in CREATE DATABASE Yushu Chen <[email protected]>
2026-05-25 18:42 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox