diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 3b0324ce18..4982fc7eb1 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -943,7 +943,7 @@ cache_locale_time(void) } -#if defined(WIN32) && defined(LC_MESSAGES) +#if defined(WIN32) /* * Convert a Windows setlocale() argument to a Unix-style one. * @@ -1692,6 +1692,16 @@ get_collation_actual_version(char collprovider, const char *collcollate) */ NLSVERSIONINFOEX version = {sizeof(NLSVERSIONINFOEX)}; WCHAR wide_collcollate[LOCALE_NAME_MAX_LENGTH]; + char *shortlocale = IsoLocaleName(collcollate); + char *underscore; + + /* + * GetNLSVersionEx wants - format, whereas the ISO + * format is _. So replace the _ with - + */ + underscore = strchr(shortlocale, '_'); + if (underscore) + *underscore = '-'; /* These would be invalid arguments, but have no version. */ if (pg_strcasecmp("c", collcollate) == 0 || @@ -1699,12 +1709,12 @@ get_collation_actual_version(char collprovider, const char *collcollate) return NULL; /* For all other names, ask the OS. */ - MultiByteToWideChar(CP_ACP, 0, collcollate, -1, wide_collcollate, + MultiByteToWideChar(CP_ACP, 0, shortlocale, -1, wide_collcollate, LOCALE_NAME_MAX_LENGTH); if (!GetNLSVersionEx(COMPARE_STRING, wide_collcollate, &version)) ereport(ERROR, (errmsg("could not get collation version for locale \"%s\": error code %lu", - collcollate, + shortlocale, GetLastError()))); collversion = psprintf("%d.%d,%d.%d", (version.dwNLSVersion >> 8) & 0xFFFF,