aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-09-03 16:38:55 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-09-03 16:39:04 -0400
commit2cc018ba8f80a5236faf2c58dfcd18fee581dbbc (patch)
tree3f050a83d5df145a0a513bbf3af5f4dcb076f88c
parent67c33a114f38edbd66f68d7b2c0cb7b03611ec48 (diff)
downloadpostgresql-2cc018ba8f80a5236faf2c58dfcd18fee581dbbc.tar.gz
postgresql-2cc018ba8f80a5236faf2c58dfcd18fee581dbbc.zip
Disallow creating an ICU collation if the DB encoding won't support it.
Previously this was allowed, but the collation effectively vanished into the ether because of the way lookup_collation() works: you could not use the collation, nor even drop it. Seems better to give an error up front than to leave the user wondering why it doesn't work. (Because this test is in DefineCollation not CreateCollation, it does not prevent pg_import_system_collations from creating ICU collations, regardless of the initially-chosen encoding.) Per bug #17170 from Andrew Bille. Back-patch to v10 where ICU support was added. Discussion: https://postgr.es/m/17170-95845cf3f0a9c36d@postgresql.org
-rw-r--r--src/backend/commands/collationcmds.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index ebb0994db32..666bcb4971b 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -208,7 +208,26 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
if (!fromEl)
{
if (collprovider == COLLPROVIDER_ICU)
+ {
+#ifdef USE_ICU
+ /*
+ * We could create ICU collations with collencoding == database
+ * encoding, but it seems better to use -1 so that it matches the
+ * way initdb would create ICU collations. However, only allow
+ * one to be created when the current database's encoding is
+ * supported. Otherwise the collation is useless, plus we get
+ * surprising behaviors like not being able to drop the collation.
+ *
+ * Skip this test when !USE_ICU, because the error we want to
+ * throw for that isn't thrown till later.
+ */
+ if (!is_encoding_supported_by_icu(GetDatabaseEncoding()))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("current database's encoding is not supported with this provider")));
+#endif
collencoding = -1;
+ }
else
{
collencoding = GetDatabaseEncoding();