Commit 4442e197 authored by Peter Eisentraut's avatar Peter Eisentraut

When creating a collation, check that the locales can be loaded

This is the same check that would happen later when the collation is
used, but it's friendlier to check the collation already when it is
created.
parent bd58d9d8
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "postgres.h" #include "postgres.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "access/xact.h"
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/pg_locale.h"
#include "utils/syscache.h" #include "utils/syscache.h"
static void AlterCollationOwner_internal(Relation rel, Oid collationOid, static void AlterCollationOwner_internal(Relation rel, Oid collationOid,
...@@ -51,6 +53,7 @@ DefineCollation(List *names, List *parameters) ...@@ -51,6 +53,7 @@ DefineCollation(List *names, List *parameters)
DefElem *lcctypeEl = NULL; DefElem *lcctypeEl = NULL;
char *collcollate = NULL; char *collcollate = NULL;
char *collctype = NULL; char *collctype = NULL;
Oid newoid;
collNamespace = QualifiedNameGetCreationNamespace(names, &collName); collNamespace = QualifiedNameGetCreationNamespace(names, &collName);
...@@ -130,12 +133,16 @@ DefineCollation(List *names, List *parameters) ...@@ -130,12 +133,16 @@ DefineCollation(List *names, List *parameters)
check_encoding_locale_matches(GetDatabaseEncoding(), collcollate, collctype); check_encoding_locale_matches(GetDatabaseEncoding(), collcollate, collctype);
CollationCreate(collName, newoid = CollationCreate(collName,
collNamespace, collNamespace,
GetUserId(), GetUserId(),
GetDatabaseEncoding(), GetDatabaseEncoding(),
collcollate, collcollate,
collctype); collctype);
/* check that the locales can be loaded */
CommandCounterIncrement();
pg_newlocale_from_collation(newoid);
} }
/* /*
......
...@@ -744,6 +744,8 @@ ERROR: encoding UTF8 does not match locale en_US ...@@ -744,6 +744,8 @@ ERROR: encoding UTF8 does not match locale en_US
DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1. DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1.
CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail
ERROR: parameter "lc_ctype" must be specified ERROR: parameter "lc_ctype" must be specified
CREATE COLLATION testx (locale = 'nonsense'); -- fail
ERROR: could not create locale "nonsense": No such file or directory
CREATE COLLATION test4 FROM nonsense; CREATE COLLATION test4 FROM nonsense;
ERROR: collation "nonsense" for current database encoding "UTF8" does not exist ERROR: collation "nonsense" for current database encoding "UTF8" does not exist
CREATE COLLATION test5 FROM test0; CREATE COLLATION test5 FROM test0;
......
...@@ -234,6 +234,7 @@ CREATE COLLATION test0 (locale = 'en_US.utf8'); -- fail ...@@ -234,6 +234,7 @@ CREATE COLLATION test0 (locale = 'en_US.utf8'); -- fail
CREATE COLLATION test1 (lc_collate = 'en_US.utf8', lc_ctype = 'de_DE.utf8'); CREATE COLLATION test1 (lc_collate = 'en_US.utf8', lc_ctype = 'de_DE.utf8');
CREATE COLLATION test2 (locale = 'en_US'); -- fail CREATE COLLATION test2 (locale = 'en_US'); -- fail
CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail
CREATE COLLATION testx (locale = 'nonsense'); -- fail
CREATE COLLATION test4 FROM nonsense; CREATE COLLATION test4 FROM nonsense;
CREATE COLLATION test5 FROM test0; CREATE COLLATION test5 FROM test0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment