Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0333a73

Browse files
committed
Avoid conflicts with collation aliases generated by stripping.
This resulted in failures depending on the order of "locale -a" output.The original coding in initdb sorted the results, but that should beunnecessary as long as "locale -a" doesn't print duplicate names. Theoriginal entries will then all be non-dups, and while we might generateduplicate aliases by stripping, they should be for different encodings andthus not conflict. Even if the latter assumption fails somehow, it won'tbe fatal because we're using if_not_exists mode for the aliases.Discussion:https://postgr.es/m/26116.1484751196%40sss.pgh.pa.us
1 parent215b43c commit0333a73

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

‎src/backend/commands/collationcmds.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,17 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
224224
{
225225
#if defined(HAVE_LOCALE_T)&& !defined(WIN32)
226226
boolif_not_exists=PG_GETARG_BOOL(0);
227-
Oidnspid=PG_GETARG_OID(1);
227+
Oidnspid=PG_GETARG_OID(1);
228228

229229
FILE*locale_a_handle;
230230
charlocalebuf[NAMEDATALEN];/* we assume ASCII so this is fine */
231231
intcount=0;
232+
List*aliaslist=NIL;
233+
List*localelist=NIL;
234+
List*enclist=NIL;
235+
ListCell*lca,
236+
*lcl,
237+
*lce;
232238
#endif
233239

234240
if (!superuser())
@@ -306,26 +312,36 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
306312
* ease of use. Note that collation names are unique per encoding
307313
* only, so this doesn't clash with "en_US" for LATIN1, say.
308314
*
309-
* This always runs in "if not exists" mode, to skip aliases that
310-
* conflict with an existing locale name for the same encoding. For
311-
* example, "br_FR.iso88591" is normalized to "br_FR", both for
312-
* encoding LATIN1. But the unnormalized locale "br_FR" already
313-
* exists for LATIN1.
315+
* However, it might conflict with a name we'll see later in the
316+
* "locale -a" output. So save up the aliases and try to add them
317+
* after we've read all the output.
314318
*/
315319
if (normalize_locale_name(alias,localebuf))
316320
{
317-
CollationCreate(alias,nspid,GetUserId(),enc,
318-
localebuf,localebuf, true);
319-
CommandCounterIncrement();
321+
aliaslist=lappend(aliaslist,pstrdup(alias));
322+
localelist=lappend(localelist,pstrdup(localebuf));
323+
enclist=lappend_int(enclist,enc);
320324
}
321325
}
322326

323327
ClosePipeStream(locale_a_handle);
324328

329+
/* Now try to add any aliases we created */
330+
forthree(lca,aliaslist,lcl,localelist,lce,enclist)
331+
{
332+
char*alias= (char*)lfirst(lca);
333+
char*locale= (char*)lfirst(lcl);
334+
intenc=lfirst_int(lce);
335+
336+
CollationCreate(alias,nspid,GetUserId(),enc,
337+
locale,locale, true);
338+
CommandCounterIncrement();
339+
}
340+
325341
if (count==0)
326342
ereport(ERROR,
327343
(errmsg("no usable system locales were found")));
328-
#endif/* not HAVE_LOCALE_T && not WIN32 */
344+
#endif/* not HAVE_LOCALE_T && not WIN32 */
329345

330346
PG_RETURN_VOID();
331347
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp