Skip to content

Commit 3ebea75

Browse files
committed
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 5a38104) 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
1 parent 71aa2e1 commit 3ebea75

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ static pg_locale_t default_locale = NULL;
134134
static bool CurrentLocaleConvValid = false;
135135
static bool CurrentLCTimeValid = false;
136136

137+
static struct pg_locale_struct c_locale = {
138+
.provider = COLLPROVIDER_LIBC,
139+
.deterministic = true,
140+
.collate_is_c = true,
141+
.ctype_is_c = true,
142+
};
143+
137144
/* Cache for collation-related knowledge */
138145

139146
typedef struct
@@ -1194,6 +1201,13 @@ pg_newlocale_from_collation(Oid collid)
11941201
if (collid == DEFAULT_COLLATION_OID)
11951202
return default_locale;
11961203

1204+
/*
1205+
* Some callers expect C_COLLATION_OID to succeed even without catalog
1206+
* access.
1207+
*/
1208+
if (collid == C_COLLATION_OID)
1209+
return &c_locale;
1210+
11971211
if (!OidIsValid(collid))
11981212
elog(ERROR, "cache lookup failed for collation %u", collid);
11991213

0 commit comments

Comments
 (0)