From 46a44dc372033da9bd8b9840711e560c9d73e768 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Fri, 29 Mar 2024 10:52:24 -0700 Subject: [PATCH] Use version for builtin collations. Given that the version field already exists, there's little reason not to use it. Suggestion from Peter Eisentraut. Discussion: https://postgr.es/m/613c120a-5413-4fa7-a501-6590eae558f8@eisentraut.org Reviewed-by: Peter Eisentraut --- src/backend/utils/adt/pg_locale.c | 14 ++++++++++++-- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_collation.dat | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index e10d328fc3..377f5837a0 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -1732,13 +1732,23 @@ get_collation_actual_version(char collprovider, const char *collcollate) /* * The only two supported locales (C and C.UTF-8) are both based on memcmp - * and are not expected to change. + * and are not expected to change, but track the version anyway. * * Note that the character semantics may change for some locales, but the * collation version only tracks changes to sort order. */ if (collprovider == COLLPROVIDER_BUILTIN) - return NULL; + { + if (strcmp(collcollate, "C") == 0) + return "1"; + else if (strcmp(collcollate, "C.UTF-8") == 0) + return "1"; + else + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("invalid locale name \"%s\" for builtin provider", + collcollate))); + } #ifdef USE_ICU if (collprovider == COLLPROVIDER_ICU) diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index fd4a482d90..7d8e002c77 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202403272 +#define CATALOG_VERSION_NO 202403291 #endif diff --git a/src/include/catalog/pg_collation.dat b/src/include/catalog/pg_collation.dat index 083b0cdcca..dcf554bbd5 100644 --- a/src/include/catalog/pg_collation.dat +++ b/src/include/catalog/pg_collation.dat @@ -25,13 +25,13 @@ collcollate => 'POSIX', collctype => 'POSIX' }, { oid => '962', descr => 'sorts by Unicode code point, C character semantics', collname => 'ucs_basic', collprovider => 'b', collencoding => '6', - colllocale => 'C' }, + colllocale => 'C', collversion => '1' }, { oid => '963', descr => 'sorts using the Unicode Collation Algorithm with default settings', collname => 'unicode', collprovider => 'i', collencoding => '-1', colllocale => 'und' }, { oid => '811', descr => 'sorts by Unicode code point; Unicode and POSIX character semantics', collname => 'pg_c_utf8', collprovider => 'b', collencoding => '6', - colllocale => 'C.UTF-8' }, + colllocale => 'C.UTF-8', collversion => '1' }, ]