1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Call pg_newlocale_from_collation() also with default collation

Previously, callers of pg_newlocale_from_collation() did not call it
if the collation was DEFAULT_COLLATION_OID and instead proceeded with
a pg_locale_t of 0.  Instead, now we call it anyway and have it return
0 if the default collation was passed.  It already did this, so we
just have to adjust the callers.  This simplifies all the call sites
and also makes future enhancements easier.

After discussion and testing, the previous comment in pg_locale.c
about avoiding this for performance reasons may have been mistaken
since it was testing a very different patch version way back when.

Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://www.postgresql.org/message-id/ed3baa81-7fac-7788-cc12-41e3f7917e34@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2022-01-20 09:38:05 +01:00
parent b2a76bb7d0
commit b99ccd2cb2
8 changed files with 135 additions and 132 deletions

View File

@ -1641,6 +1641,19 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
if (!buff)
return NULL;
if (!OidIsValid(collid))
{
/*
* This typically means that the parser could not resolve a
* conflict of implicit collations, so report it that way.
*/
ereport(ERROR,
(errcode(ERRCODE_INDETERMINATE_COLLATION),
errmsg("could not determine which collation to use for %s function",
"lower()"),
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
/* C/POSIX collations use this path regardless of database encoding */
if (lc_ctype_is_c(collid))
{
@ -1648,24 +1661,9 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
}
else
{
pg_locale_t mylocale = 0;
pg_locale_t mylocale;
if (collid != DEFAULT_COLLATION_OID)
{
if (!OidIsValid(collid))
{
/*
* This typically means that the parser could not resolve a
* conflict of implicit collations, so report it that way.
*/
ereport(ERROR,
(errcode(ERRCODE_INDETERMINATE_COLLATION),
errmsg("could not determine which collation to use for %s function",
"lower()"),
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
mylocale = pg_newlocale_from_collation(collid);
}
mylocale = pg_newlocale_from_collation(collid);
#ifdef USE_ICU
if (mylocale && mylocale->provider == COLLPROVIDER_ICU)
@ -1765,6 +1763,19 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
if (!buff)
return NULL;
if (!OidIsValid(collid))
{
/*
* This typically means that the parser could not resolve a
* conflict of implicit collations, so report it that way.
*/
ereport(ERROR,
(errcode(ERRCODE_INDETERMINATE_COLLATION),
errmsg("could not determine which collation to use for %s function",
"upper()"),
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
/* C/POSIX collations use this path regardless of database encoding */
if (lc_ctype_is_c(collid))
{
@ -1772,24 +1783,9 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
}
else
{
pg_locale_t mylocale = 0;
pg_locale_t mylocale;
if (collid != DEFAULT_COLLATION_OID)
{
if (!OidIsValid(collid))
{
/*
* This typically means that the parser could not resolve a
* conflict of implicit collations, so report it that way.
*/
ereport(ERROR,
(errcode(ERRCODE_INDETERMINATE_COLLATION),
errmsg("could not determine which collation to use for %s function",
"upper()"),
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
mylocale = pg_newlocale_from_collation(collid);
}
mylocale = pg_newlocale_from_collation(collid);
#ifdef USE_ICU
if (mylocale && mylocale->provider == COLLPROVIDER_ICU)
@ -1890,6 +1886,19 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
if (!buff)
return NULL;
if (!OidIsValid(collid))
{
/*
* This typically means that the parser could not resolve a
* conflict of implicit collations, so report it that way.
*/
ereport(ERROR,
(errcode(ERRCODE_INDETERMINATE_COLLATION),
errmsg("could not determine which collation to use for %s function",
"initcap()"),
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
/* C/POSIX collations use this path regardless of database encoding */
if (lc_ctype_is_c(collid))
{
@ -1897,24 +1906,9 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
}
else
{
pg_locale_t mylocale = 0;
pg_locale_t mylocale;
if (collid != DEFAULT_COLLATION_OID)
{
if (!OidIsValid(collid))
{
/*
* This typically means that the parser could not resolve a
* conflict of implicit collations, so report it that way.
*/
ereport(ERROR,
(errcode(ERRCODE_INDETERMINATE_COLLATION),
errmsg("could not determine which collation to use for %s function",
"initcap()"),
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
mylocale = pg_newlocale_from_collation(collid);
}
mylocale = pg_newlocale_from_collation(collid);
#ifdef USE_ICU
if (mylocale && mylocale->provider == COLLPROVIDER_ICU)