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
errhint("Use the COLLATE clause to set the collation explicitly.")));
}
- if (collation == C_COLLATION_OID)
- {
- /*
- * 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)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("nondeterministic collations are not supported for regular expressions")));
+ locale = pg_newlocale_from_collation(collation);
- if (locale->ctype_is_c)
- {
- /*
- * C/POSIX collations use this path regardless of database
- * encoding
- */
- locale = &dummy_c_locale;
- }
- }
+ if (!locale->deterministic)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("nondeterministic collations are not supported for regular expressions")));
pg_regex_locale = locale;
}
static bool CurrentLocaleConvValid = 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 */
typedef struct
if (collid == DEFAULT_COLLATION_OID)
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))
elog(ERROR, "cache lookup failed for collation %u", collid);