mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Special case C_COLLATION_OID in pg_newlocale_from_collation().
Allow pg_newlocale_from_collation(C_COLLATION_OID) to work even if
there's no catalog access, which some extensions expect.
Not known to be a bug without extensions involved, but backport to 18.
Also corrects an issue in master with dummy_c_locale (introduced in
commit 5a38104b36) where deterministic was not set. That wasn't a bug,
but could have been if that structure was used more widely.
Reported-by: Alexander Kukushkin <cyberdemn@gmail.com>
Reviewed-by: Alexander Kukushkin <cyberdemn@gmail.com>
Discussion: https://postgr.es/m/CAFh8B=nj966ECv5vi_u3RYij12v0j-7NPZCXLYzNwOQp9AcPWQ@mail.gmail.com
Backpatch-through: 18
This commit is contained in:
@@ -23,11 +23,6 @@
|
|||||||
|
|
||||||
static pg_locale_t pg_regex_locale;
|
static pg_locale_t pg_regex_locale;
|
||||||
|
|
||||||
static struct pg_locale_struct dummy_c_locale = {
|
|
||||||
.collate_is_c = true,
|
|
||||||
.ctype_is_c = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* pg_set_regex_collation: set collation for these functions to obey
|
* pg_set_regex_collation: set collation for these functions to obey
|
||||||
@@ -53,33 +48,12 @@ pg_set_regex_collation(Oid collation)
|
|||||||
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collation == C_COLLATION_OID)
|
locale = pg_newlocale_from_collation(collation);
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Some callers expect regexes to work for C_COLLATION_OID before
|
|
||||||
* catalog access is available, so we can't call
|
|
||||||
* pg_newlocale_from_collation().
|
|
||||||
*/
|
|
||||||
locale = &dummy_c_locale;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
locale = pg_newlocale_from_collation(collation);
|
|
||||||
|
|
||||||
if (!locale->deterministic)
|
if (!locale->deterministic)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg("nondeterministic collations are not supported for regular expressions")));
|
errmsg("nondeterministic collations are not supported for regular expressions")));
|
||||||
|
|
||||||
if (locale->ctype_is_c)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* C/POSIX collations use this path regardless of database
|
|
||||||
* encoding
|
|
||||||
*/
|
|
||||||
locale = &dummy_c_locale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pg_regex_locale = locale;
|
pg_regex_locale = locale;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,12 @@ static pg_locale_t default_locale = NULL;
|
|||||||
static bool CurrentLocaleConvValid = false;
|
static bool CurrentLocaleConvValid = false;
|
||||||
static bool CurrentLCTimeValid = false;
|
static bool CurrentLCTimeValid = false;
|
||||||
|
|
||||||
|
static struct pg_locale_struct c_locale = {
|
||||||
|
.deterministic = true,
|
||||||
|
.collate_is_c = true,
|
||||||
|
.ctype_is_c = true,
|
||||||
|
};
|
||||||
|
|
||||||
/* Cache for collation-related knowledge */
|
/* Cache for collation-related knowledge */
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -1185,6 +1191,13 @@ pg_newlocale_from_collation(Oid collid)
|
|||||||
if (collid == DEFAULT_COLLATION_OID)
|
if (collid == DEFAULT_COLLATION_OID)
|
||||||
return default_locale;
|
return default_locale;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some callers expect C_COLLATION_OID to succeed even without catalog
|
||||||
|
* access.
|
||||||
|
*/
|
||||||
|
if (collid == C_COLLATION_OID)
|
||||||
|
return &c_locale;
|
||||||
|
|
||||||
if (!OidIsValid(collid))
|
if (!OidIsValid(collid))
|
||||||
elog(ERROR, "cache lookup failed for collation %u", collid);
|
elog(ERROR, "cache lookup failed for collation %u", collid);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user