typedefstruct
{ char *localename; /* name of locale, as per "locale -a" */ char *alias; /* shortened alias for same */ int enc; /* encoding */
} CollAliasData;
if (localeEl && (lccollateEl || lcctypeEl))
ereport(ERROR,
errcode(ERRCODE_SYNTAX_ERROR),
errmsg("conflicting or redundant options"),
errdetail("LOCALE cannot be specified together with LC_COLLATE or LC_CTYPE."));
if (fromEl && list_length(parameters) != 1)
ereport(ERROR,
errcode(ERRCODE_SYNTAX_ERROR),
errmsg("conflicting or redundant options"),
errdetail("FROM cannot be specified together with any other options."));
if (fromEl)
{
Oid collid;
HeapTuple tp;
Datum datum; bool isnull;
collid = get_collation_oid(defGetQualifiedName(fromEl), false);
tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid)); if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for collation %u", collid);
if (localeEl)
{ if (collprovider == COLLPROVIDER_LIBC)
{
collcollate = defGetString(localeEl);
collctype = defGetString(localeEl);
} else
colllocale = defGetString(localeEl);
}
if (lccollateEl)
collcollate = defGetString(lccollateEl);
if (lcctypeEl)
collctype = defGetString(lcctypeEl);
if (collprovider == COLLPROVIDER_BUILTIN)
{ if (!colllocale)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("parameter \"%s\" must be specified", "locale")));
colllocale = builtin_validate_locale(GetDatabaseEncoding(),
colllocale);
} elseif (collprovider == COLLPROVIDER_LIBC)
{ if (!collcollate)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("parameter \"%s\" must be specified", "lc_collate")));
if (!collctype)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("parameter \"%s\" must be specified", "lc_ctype")));
} elseif (collprovider == COLLPROVIDER_ICU)
{ if (!colllocale)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("parameter \"%s\" must be specified", "locale")));
/* *SubroutineforALTERCOLLATIONSETSCHEMAandRENAME * *Isthereacollationwiththesamenameofthegivencollationalreadyin *thegivennamespace?Ifso,raiseanappropriateerrormessage.
*/ void
IsThereCollationInNamespace(constchar *collname, Oid nspOid)
{ /* make sure the name doesn't already exist in new schema */ if (SearchSysCacheExists3(COLLNAMEENCNSP,
CStringGetDatum(collname),
Int32GetDatum(GetDatabaseEncoding()),
ObjectIdGetDatum(nspOid)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("collation \"%s\" for encoding \"%s\" already exists in schema \"%s\"",
collname, GetDatabaseEncodingName(),
get_namespace_name(nspOid))));
/* mustn't match an any-encoding entry, either */ if (SearchSysCacheExists3(COLLNAMEENCNSP,
CStringGetDatum(collname),
Int32GetDatum(-1),
ObjectIdGetDatum(nspOid)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("collation \"%s\" already exists in schema \"%s\"",
collname, get_namespace_name(nspOid))));
}
if (collForm->collprovider == COLLPROVIDER_LIBC)
datum = SysCacheGetAttrNotNull(COLLOID, tup, Anum_pg_collation_collcollate); else
datum = SysCacheGetAttrNotNull(COLLOID, tup, Anum_pg_collation_colllocale);
/* comparing localename is enough because other fields are derived */ return strcmp(ca->localename, cb->localename);
} #endif/* READ_LOCALE_A_OUTPUT */
status = U_ZERO_ERROR;
len_uchar = uloc_getDisplayName(localename, "en",
displayname, lengthof(displayname),
&status); if (U_FAILURE(status)) return NULL; /* no good reason to raise an error */
/* Check for non-ASCII comment (can't use pg_is_ascii for this) */ for (i = 0; i < len_uchar; i++)
{ if (displayname[i] > 127) return NULL;
}
/* OK, transcribe */
result = palloc(len_uchar + 1); for (i = 0; i < len_uchar; i++)
result[i] = displayname[i];
result[len_uchar] = '\0';
return result;
} #endif/* USE_ICU */
/* *Createanewcollationusingtheinputlocale'locale'.(subroutinefor *pg_import_system_collations()) * *'nspid'isthenamespaceidwherethecollationwillbecreated. * *'nvalidp'isincrementedifthelocalehasavalidencoding. * *'ncreatedp'isincrementedifthecollationisactuallycreated.Ifthe *collationalreadyexistsitwillquietlydonothing. * *Thereturnedvalueistheencodingofthelocale,-1ifthelocaleisnot *validforcreatingacollation. *
*/
pg_attribute_unused() staticint
create_collation_from_locale(constchar *locale, int nspid, int *nvalidp, int *ncreatedp)
{ int enc;
Oid collid;
/* *Somesystemshavelocalenamesthatdon'tconsistentirelyofASCII *letters(suchas"bokmål"or"français").Thisispretty *silly,sinceweneedthelocaleitselftointerpretthenon-ASCII *characters.Wecan'tdomuchwiththose,sowefilterthemout.
*/ if (!pg_is_ascii(locale))
{
elog(DEBUG1, "skipping locale with non-ASCII name: \"%s\"", locale); return -1;
}
enc = pg_get_encoding_from_locale(locale, false); if (enc < 0)
{
elog(DEBUG1, "skipping locale with unrecognized encoding: \"%s\"", locale); return -1;
} if (!PG_VALID_BE_ENCODING(enc))
{
elog(DEBUG1, "skipping locale with client-only encoding: \"%s\"", locale); return -1;
} if (enc == PG_SQL_ASCII) return -1; /* C/POSIX are already in the catalog */
/* count valid locales found in operating system */
(*nvalidp)++;
/* Must do CCI between inserts to handle duplicates correctly */
CommandCounterIncrement();
}
return enc;
}
#ifdef ENUM_SYSTEM_LOCALE /* parameter to be passed to the callback function win32_read_locale() */ typedefstruct
{
Oid nspid; int *ncreatedp; int *nvalidp;
} CollParam;
/* *pg_import_system_collations:addknownsystemcollationstopg_collation
*/
Datum
pg_import_system_collations(PG_FUNCTION_ARGS)
{
Oid nspid = PG_GETARG_OID(0); int ncreated = 0;
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to import system collations")));
if (!SearchSysCacheExists1(NAMESPACEOID, ObjectIdGetDatum(nspid)))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema with OID %u does not exist", nspid)));
/* Load collations known to libc, using "locale -a" to enumerate them */ #ifdef READ_LOCALE_A_OUTPUT
{
FILE *locale_a_handle; char localebuf[LOCALE_NAME_BUFLEN]; int nvalid = 0;
Oid collid;
CollAliasData *aliases; int naliases,
maxaliases,
i;
/* Now add aliases, ignoring any that match pre-existing entries */ for (i = 0; i < naliases; i++)
{ char *locale = aliases[i].localename; char *alias = aliases[i].alias; int enc = aliases[i].enc;
/* Give a warning if "locale -a" seems to be malfunctioning */ if (nvalid == 0)
ereport(WARNING,
(errmsg("no usable system locales were found")));
} #endif/* READ_LOCALE_A_OUTPUT */
/* Give a warning if EnumSystemLocalesEx seems to be malfunctioning */ if (nvalid == 0)
ereport(WARNING,
(errmsg("no usable system locales were found")));
} #endif/* ENUM_SYSTEM_LOCALE */
PG_RETURN_INT32(ncreated);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.