aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/formatting.c78
-rw-r--r--src/backend/utils/adt/pg_locale.c14
-rw-r--r--src/backend/utils/adt/varlena.c13
3 files changed, 94 insertions, 11 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 54783103a2c..45e36f92e50 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1503,7 +1503,20 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
size_t result_size;
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 lower() function"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
/* Overflow paranoia */
if ((nbytes + 1) > (INT_MAX / sizeof(wchar_t)))
@@ -1540,7 +1553,20 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
char *p;
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 lower() function"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
result = pnstrdup(buff, nbytes);
@@ -1598,7 +1624,20 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
size_t result_size;
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 upper() function"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
/* Overflow paranoia */
if ((nbytes + 1) > (INT_MAX / sizeof(wchar_t)))
@@ -1635,7 +1674,20 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
char *p;
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 upper() function"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
result = pnstrdup(buff, nbytes);
@@ -1705,7 +1757,20 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
size_t result_size;
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 initcap() function"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
/* Overflow paranoia */
if ((nbytes + 1) > (INT_MAX / sizeof(wchar_t)))
@@ -1754,7 +1819,20 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
char *p;
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 initcap() function"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
result = pnstrdup(buff, nbytes);
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 15d347c4f89..163856d5b18 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -932,21 +932,13 @@ pg_newlocale_from_collation(Oid collid)
{
collation_cache_entry *cache_entry;
+ /* Callers must pass a valid OID */
+ Assert(OidIsValid(collid));
+
/* Return 0 for "default" collation, just in case caller forgets */
if (collid == DEFAULT_COLLATION_OID)
return (pg_locale_t) 0;
- /*
- * This is where we'll fail if a collation-aware function is invoked
- * and no collation OID is passed. This typically means that the
- * parser could not resolve a conflict of implicit collations, so
- * report it that way.
- */
- if (!OidIsValid(collid))
- ereport(ERROR,
- (errcode(ERRCODE_INDETERMINATE_COLLATION),
- errmsg("locale operation to be invoked, but no collation was derived")));
-
cache_entry = lookup_collation_cache(collid, false);
if (cache_entry->locale == 0)
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 8a7a3cf45bf..3587fe45951 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -1302,7 +1302,20 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
pg_locale_t mylocale = 0;
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 string comparison"),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
mylocale = pg_newlocale_from_collation(collid);
+ }
#ifdef WIN32
/* Win32 does not have UTF-8, so we need to map to UTF-16 */