aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2020-03-25 15:53:24 +1300
committerThomas Munro <tmunro@postgresql.org>2020-03-25 15:53:24 +1300
commit382a821907e76bf6068492a164fdfc57578391f4 (patch)
tree697544cff679ca2ab357e6d68f22146f1d094342 /src/backend/utils/adt/pg_locale.c
parentdd8e19132acfbb28d579288a412ed6c0a5ea338b (diff)
downloadpostgresql-382a821907e76bf6068492a164fdfc57578391f4.tar.gz
postgresql-382a821907e76bf6068492a164fdfc57578391f4.zip
Allow NULL version for individual collations.
Remove the documented restriction that collation providers must either return NULL for all collations or non-NULL for all collations. Use NULL for glibc collations like "C.UTF-8", which might otherwise lead future proposed commits to force unnecessary index rebuilds. Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com> Discussion: https://postgr.es/m/CA%2BhUKGJvqup3s%2BJowVTcacZADO6dOhfdBmvOPHLS3KXUJu41Jw%40mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 64fd3ae18a8..b42122f9cea 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1505,10 +1505,6 @@ pg_newlocale_from_collation(Oid collid)
/*
* Get provider-specific collation version string for the given collation from
* the operating system/library.
- *
- * A particular provider must always either return a non-NULL string or return
- * NULL (if it doesn't support versions). It must not return NULL for some
- * collcollate and not NULL for others.
*/
char *
get_collation_actual_version(char collprovider, const char *collcollate)
@@ -1540,6 +1536,23 @@ get_collation_actual_version(char collprovider, const char *collcollate)
if (collprovider == COLLPROVIDER_LIBC)
{
#if defined(__GLIBC__)
+ char *copy = pstrdup(collcollate);
+ char *copy_suffix = strstr(copy, ".");
+ bool need_version = true;
+
+ /*
+ * Check for names like C.UTF-8 by chopping off the encoding suffix on
+ * our temporary copy, so we can skip the version.
+ */
+ if (copy_suffix)
+ *copy_suffix = '\0';
+ if (pg_strcasecmp("c", copy) == 0 ||
+ pg_strcasecmp("posix", copy) == 0)
+ need_version = false;
+ pfree(copy);
+ if (!need_version)
+ return NULL;
+
/* Use the glibc version because we don't have anything better. */
collversion = pstrdup(gnu_get_libc_version());
#endif