@@ -1641,31 +1641,29 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
16411641 if (!buff )
16421642 return NULL ;
16431643
1644+ if (!OidIsValid (collid ))
1645+ {
1646+ /*
1647+ * This typically means that the parser could not resolve a
1648+ * conflict of implicit collations, so report it that way.
1649+ */
1650+ ereport (ERROR ,
1651+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1652+ errmsg ("could not determine which collation to use for %s function" ,
1653+ "lower()" ),
1654+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1655+ }
1656+
16441657 /* C/POSIX collations use this path regardless of database encoding */
16451658 if (lc_ctype_is_c (collid ))
16461659 {
16471660 result = asc_tolower (buff , nbytes );
16481661 }
16491662 else
16501663 {
1651- pg_locale_t mylocale = 0 ;
1664+ pg_locale_t mylocale ;
16521665
1653- if (collid != DEFAULT_COLLATION_OID )
1654- {
1655- if (!OidIsValid (collid ))
1656- {
1657- /*
1658- * This typically means that the parser could not resolve a
1659- * conflict of implicit collations, so report it that way.
1660- */
1661- ereport (ERROR ,
1662- (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1663- errmsg ("could not determine which collation to use for %s function" ,
1664- "lower()" ),
1665- errhint ("Use the COLLATE clause to set the collation explicitly." )));
1666- }
1667- mylocale = pg_newlocale_from_collation (collid );
1668- }
1666+ mylocale = pg_newlocale_from_collation (collid );
16691667
16701668#ifdef USE_ICU
16711669 if (mylocale && mylocale -> provider == COLLPROVIDER_ICU )
@@ -1765,31 +1763,29 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
17651763 if (!buff )
17661764 return NULL ;
17671765
1766+ if (!OidIsValid (collid ))
1767+ {
1768+ /*
1769+ * This typically means that the parser could not resolve a
1770+ * conflict of implicit collations, so report it that way.
1771+ */
1772+ ereport (ERROR ,
1773+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1774+ errmsg ("could not determine which collation to use for %s function" ,
1775+ "upper()" ),
1776+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1777+ }
1778+
17681779 /* C/POSIX collations use this path regardless of database encoding */
17691780 if (lc_ctype_is_c (collid ))
17701781 {
17711782 result = asc_toupper (buff , nbytes );
17721783 }
17731784 else
17741785 {
1775- pg_locale_t mylocale = 0 ;
1786+ pg_locale_t mylocale ;
17761787
1777- if (collid != DEFAULT_COLLATION_OID )
1778- {
1779- if (!OidIsValid (collid ))
1780- {
1781- /*
1782- * This typically means that the parser could not resolve a
1783- * conflict of implicit collations, so report it that way.
1784- */
1785- ereport (ERROR ,
1786- (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1787- errmsg ("could not determine which collation to use for %s function" ,
1788- "upper()" ),
1789- errhint ("Use the COLLATE clause to set the collation explicitly." )));
1790- }
1791- mylocale = pg_newlocale_from_collation (collid );
1792- }
1788+ mylocale = pg_newlocale_from_collation (collid );
17931789
17941790#ifdef USE_ICU
17951791 if (mylocale && mylocale -> provider == COLLPROVIDER_ICU )
@@ -1890,31 +1886,29 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
18901886 if (!buff )
18911887 return NULL ;
18921888
1889+ if (!OidIsValid (collid ))
1890+ {
1891+ /*
1892+ * This typically means that the parser could not resolve a
1893+ * conflict of implicit collations, so report it that way.
1894+ */
1895+ ereport (ERROR ,
1896+ (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1897+ errmsg ("could not determine which collation to use for %s function" ,
1898+ "initcap()" ),
1899+ errhint ("Use the COLLATE clause to set the collation explicitly." )));
1900+ }
1901+
18931902 /* C/POSIX collations use this path regardless of database encoding */
18941903 if (lc_ctype_is_c (collid ))
18951904 {
18961905 result = asc_initcap (buff , nbytes );
18971906 }
18981907 else
18991908 {
1900- pg_locale_t mylocale = 0 ;
1909+ pg_locale_t mylocale ;
19011910
1902- if (collid != DEFAULT_COLLATION_OID )
1903- {
1904- if (!OidIsValid (collid ))
1905- {
1906- /*
1907- * This typically means that the parser could not resolve a
1908- * conflict of implicit collations, so report it that way.
1909- */
1910- ereport (ERROR ,
1911- (errcode (ERRCODE_INDETERMINATE_COLLATION ),
1912- errmsg ("could not determine which collation to use for %s function" ,
1913- "initcap()" ),
1914- errhint ("Use the COLLATE clause to set the collation explicitly." )));
1915- }
1916- mylocale = pg_newlocale_from_collation (collid );
1917- }
1911+ mylocale = pg_newlocale_from_collation (collid );
19181912
19191913#ifdef USE_ICU
19201914 if (mylocale && mylocale -> provider == COLLPROVIDER_ICU )
0 commit comments