@@ -1503,7 +1503,20 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
15031503size_t result_size ;
15041504
15051505if (collid != DEFAULT_COLLATION_OID )
1506+ {
1507+ if (!OidIsValid (collid ))
1508+ {
1509+ /*
1510+ * This typically means that the parser could not resolve a
1511+ * conflict of implicit collations, so report it that way.
1512+ */
1513+ ereport (ERROR ,
1514+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1515+ errmsg ("could not determine which collation to use for lower() function" ),
1516+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1517+ }
15061518mylocale = pg_newlocale_from_collation (collid );
1519+ }
15071520
15081521/* Overflow paranoia */
15091522if ((nbytes + 1 )> (INT_MAX /sizeof (wchar_t )))
@@ -1540,7 +1553,20 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
15401553char * p ;
15411554
15421555if (collid != DEFAULT_COLLATION_OID )
1556+ {
1557+ if (!OidIsValid (collid ))
1558+ {
1559+ /*
1560+ * This typically means that the parser could not resolve a
1561+ * conflict of implicit collations, so report it that way.
1562+ */
1563+ ereport (ERROR ,
1564+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1565+ errmsg ("could not determine which collation to use for lower() function" ),
1566+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1567+ }
15431568mylocale = pg_newlocale_from_collation (collid );
1569+ }
15441570
15451571result = pnstrdup (buff ,nbytes );
15461572
@@ -1598,7 +1624,20 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
15981624size_t result_size ;
15991625
16001626if (collid != DEFAULT_COLLATION_OID )
1627+ {
1628+ if (!OidIsValid (collid ))
1629+ {
1630+ /*
1631+ * This typically means that the parser could not resolve a
1632+ * conflict of implicit collations, so report it that way.
1633+ */
1634+ ereport (ERROR ,
1635+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1636+ errmsg ("could not determine which collation to use for upper() function" ),
1637+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1638+ }
16011639mylocale = pg_newlocale_from_collation (collid );
1640+ }
16021641
16031642/* Overflow paranoia */
16041643if ((nbytes + 1 )> (INT_MAX /sizeof (wchar_t )))
@@ -1635,7 +1674,20 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
16351674char * p ;
16361675
16371676if (collid != DEFAULT_COLLATION_OID )
1677+ {
1678+ if (!OidIsValid (collid ))
1679+ {
1680+ /*
1681+ * This typically means that the parser could not resolve a
1682+ * conflict of implicit collations, so report it that way.
1683+ */
1684+ ereport (ERROR ,
1685+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1686+ errmsg ("could not determine which collation to use for upper() function" ),
1687+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1688+ }
16381689mylocale = pg_newlocale_from_collation (collid );
1690+ }
16391691
16401692result = pnstrdup (buff ,nbytes );
16411693
@@ -1705,7 +1757,20 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
17051757size_t result_size ;
17061758
17071759if (collid != DEFAULT_COLLATION_OID )
1760+ {
1761+ if (!OidIsValid (collid ))
1762+ {
1763+ /*
1764+ * This typically means that the parser could not resolve a
1765+ * conflict of implicit collations, so report it that way.
1766+ */
1767+ ereport (ERROR ,
1768+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1769+ errmsg ("could not determine which collation to use for initcap() function" ),
1770+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1771+ }
17081772mylocale = pg_newlocale_from_collation (collid );
1773+ }
17091774
17101775/* Overflow paranoia */
17111776if ((nbytes + 1 )> (INT_MAX /sizeof (wchar_t )))
@@ -1754,7 +1819,20 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
17541819char * p ;
17551820
17561821if (collid != DEFAULT_COLLATION_OID )
1822+ {
1823+ if (!OidIsValid (collid ))
1824+ {
1825+ /*
1826+ * This typically means that the parser could not resolve a
1827+ * conflict of implicit collations, so report it that way.
1828+ */
1829+ ereport (ERROR ,
1830+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1831+ errmsg ("could not determine which collation to use for initcap() function" ),
1832+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1833+ }
17571834mylocale = pg_newlocale_from_collation (collid );
1835+ }
17581836
17591837result = pnstrdup (buff ,nbytes );
17601838