@@ -1595,6 +1595,7 @@ setup_collation(void)
1595
1595
size_t len ;
1596
1596
int enc ;
1597
1597
bool skip ;
1598
+ char * quoted_locale ;
1598
1599
char alias [NAMEDATALEN ];
1599
1600
1600
1601
len = strlen (localebuf );
@@ -1645,38 +1646,44 @@ setup_collation(void)
1645
1646
1646
1647
count ++ ;
1647
1648
1648
- PG_CMD_PRINTF2 ("INSERT INTO tmp_pg_collation (locale, encoding) VALUES ('%s', %d);\n" ,
1649
- escape_quotes (localebuf ), enc );
1649
+ quoted_locale = escape_quotes (localebuf );
1650
+
1651
+ PG_CMD_PRINTF3 ("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n" ,
1652
+ quoted_locale , quoted_locale , enc );
1650
1653
1651
1654
/*
1652
1655
* Generate aliases such as "en_US" in addition to "en_US.utf8" for
1653
1656
* ease of use. Note that collation names are unique per encoding
1654
1657
* only, so this doesn't clash with "en_US" for LATIN1, say.
1655
1658
*/
1656
1659
if (normalize_locale_name (alias , localebuf ))
1657
- PG_CMD_PRINTF3 ("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('%s', '%s', %d);\n" ,
1658
- escape_quotes (alias ), escape_quotes ( localebuf ) , enc );
1660
+ PG_CMD_PRINTF3 ("INSERT INTO tmp_pg_collation VALUES (E '%s', E '%s', %d);\n" ,
1661
+ escape_quotes (alias ), quoted_locale , enc );
1659
1662
}
1660
1663
1661
1664
/* Add an SQL-standard name */
1662
- PG_CMD_PRINTF1 ("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('ucs_basic', 'C', %d);\n" , PG_UTF8 );
1665
+ PG_CMD_PRINTF1 ("INSERT INTO tmp_pg_collation VALUES ('ucs_basic', 'C', %d);\n" , PG_UTF8 );
1663
1666
1664
1667
/*
1665
1668
* When copying collations to the final location, eliminate aliases that
1666
1669
* conflict with an existing locale name for the same encoding. For
1667
1670
* example, "br_FR.iso88591" is normalized to "br_FR", both for encoding
1668
1671
* LATIN1. But the unnormalized locale "br_FR" already exists for LATIN1.
1669
- * Prefer the collation that matches the OS locale name, else the first
1672
+ * Prefer the alias that matches the OS locale name, else the first locale
1670
1673
* name by sort order (arbitrary choice to be deterministic).
1674
+ *
1675
+ * Also, eliminate any aliases that conflict with pg_collation's
1676
+ * hard-wired entries for "C" etc.
1671
1677
*/
1672
1678
PG_CMD_PUTS ("INSERT INTO pg_collation (collname, collnamespace, collowner, collencoding, collcollate, collctype) "
1673
- " SELECT DISTINCT ON (final_collname, collnamespace , encoding)"
1674
- " COALESCE( collname, locale) AS final_collname , "
1679
+ " SELECT DISTINCT ON (collname , encoding)"
1680
+ " collname, "
1675
1681
" (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog') AS collnamespace, "
1676
1682
" (SELECT relowner FROM pg_class WHERE relname = 'pg_collation') AS collowner, "
1677
1683
" encoding, locale, locale "
1678
1684
" FROM tmp_pg_collation"
1679
- " ORDER BY final_collname, collnamespace, encoding, (collname = locale) DESC, locale;\n" );
1685
+ " WHERE NOT EXISTS (SELECT 1 FROM pg_collation WHERE collname = tmp_pg_collation.collname)"
1686
+ " ORDER BY collname, encoding, (collname = locale) DESC, locale;\n" );
1680
1687
1681
1688
pclose (locale_a_handle );
1682
1689
PG_CMD_CLOSE ;
0 commit comments