diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-08-01 13:51:05 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-08-01 13:51:05 -0400 |
commit | f97256570f45c33abf695a189ab11b25e6cd7985 (patch) | |
tree | 93cd212d5b2326cc78d1b3d6aaa4bd59ef625651 /src/backend/commands/collationcmds.c | |
parent | b21c569cea58a1396d9ffd8a7e7a84aa991a1123 (diff) | |
download | postgresql-f97256570f45c33abf695a189ab11b25e6cd7985.tar.gz postgresql-f97256570f45c33abf695a189ab11b25e6cd7985.zip |
Allow creation of C/POSIX collations without depending on libc behavior.
Most of our collations code has special handling for the locale names
"C" and "POSIX", allowing those collations to be used whether or not
the system libraries think those locale names are valid, or indeed
whether said libraries even have any locale support. But we missed
handling things that way in CREATE COLLATION. This meant you couldn't
clone the C/POSIX collations, nor explicitly define a new collation
using those locale names, unless the libraries allow it. That's pretty
pointless, as well as being a violation of pg_newlocale_from_collation's
API specification.
The practical effect of this change is quite limited: it allows creating
such collations even on platforms that don't HAVE_LOCALE_T, and it allows
making "POSIX" collation objects on Windows, which before this would only
let you make "C" collation objects. Hence, even though this is a bug fix
IMO, it doesn't seem worth the trouble to back-patch.
In passing, suppress the DROP CASCADE detail messages at the end of the
collation regression test. I'm surprised we've never been bit by
message ordering issues there.
Per report from Murtuza Zabuawala.
Discussion: https://postgr.es/m/CAKKotZS-wcDcofXDCH=sidiuajE+nqHn2CGjLLX78anyDmi3gQ@mail.gmail.com
Diffstat (limited to 'src/backend/commands/collationcmds.c')
-rw-r--r-- | src/backend/commands/collationcmds.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index b6c14c920df..d19a384f9c1 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -214,11 +214,15 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e if (!OidIsValid(newoid)) return InvalidObjectAddress; - ObjectAddressSet(address, CollationRelationId, newoid); - - /* check that the locales can be loaded */ + /* + * Check that the locales can be loaded. NB: pg_newlocale_from_collation + * is only supposed to be called on non-C-equivalent locales. + */ CommandCounterIncrement(); - (void) pg_newlocale_from_collation(newoid); + if (!lc_collate_is_c(newoid) || !lc_ctype_is_c(newoid)) + (void) pg_newlocale_from_collation(newoid); + + ObjectAddressSet(address, CollationRelationId, newoid); return address; } |