Tolerate version lookup failure for old style Windows locale names.
authorThomas Munro <[email protected]>
Wed, 4 Nov 2020 01:58:34 +0000 (14:58 +1300)
committerThomas Munro <[email protected]>
Wed, 4 Nov 2020 02:13:08 +0000 (15:13 +1300)
Accept that we can't get versions for such locale names for now.  Users
will need to specify the newer language tag format to enable the
collation versioning feature.  It's not clear that we can do automatic
conversion from the old style to the new style reliably enough for this
purpose.

Unfortunately, this means that collation versioning probably won't work
for the default collation unless you provide something like en-US at
initdb or CREATE DATABASE time (though, for reasons not yet understood,
it does seem to work on some systems).  It'd be nice to find a better
solution, or document this quirk if we settle on it, but this should
unbreak the 3 failing build farm animals in the meantime.

Reviewed-by: David Rowley <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAEepm%3D0uEQCpfq_%2BLYFBdArCe4Ot98t1aR4eYiYTe%3DyavQygiQ%40mail.gmail.com

src/backend/utils/adt/pg_locale.c

index 3b0324ce18ab76c976fa61299c9dc2db56a8f34d..d5a0169420a38953ea8addc1ad6ee51265ecefd3 100644 (file)
@@ -1702,10 +1702,22 @@ get_collation_actual_version(char collprovider, const char *collcollate)
        MultiByteToWideChar(CP_ACP, 0, collcollate, -1, wide_collcollate,
                            LOCALE_NAME_MAX_LENGTH);
        if (!GetNLSVersionEx(COMPARE_STRING, wide_collcollate, &version))
+       {
+           /*
+            * GetNLSVersionEx() wants a language tag such as "en-US", not a
+            * locale name like "English_United States.1252".  Until those
+            * values can be prevented from entering the system, or 100%
+            * reliably converted to the more useful tag format, tolerate the
+            * resulting error and report that we have no version data.
+            */
+           if (GetLastError() == ERROR_INVALID_PARAMETER)
+               return NULL;
+
            ereport(ERROR,
                    (errmsg("could not get collation version for locale \"%s\": error code %lu",
                            collcollate,
                            GetLastError())));
+       }
        collversion = psprintf("%d.%d,%d.%d",
                               (version.dwNLSVersion >> 8) & 0xFFFF,
                               version.dwNLSVersion & 0xFF,