v6-0004-Add-default_collation_provider-GUC.patch
text/x-patch
Filename: v6-0004-Add-default_collation_provider-GUC.patch
Type: text/x-patch
Part: 3
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v6-0004
Subject: Add default_collation_provider GUC.
| File | + | − |
|---|---|---|
| doc/src/sgml/config.sgml | 17 | 0 |
| doc/src/sgml/ref/create_collation.sgml | 11 | 4 |
| src/backend/commands/collationcmds.c | 7 | 1 |
| src/backend/utils/misc/guc_tables.c | 18 | 0 |
| src/backend/utils/misc/postgresql.conf.sample | 4 | 0 |
| src/include/commands/collationcmds.h | 2 | 0 |
| src/test/regress/expected/collate.icu.utf8.out | 25 | 0 |
| src/test/regress/sql/collate.icu.utf8.sql | 13 | 0 |
From 2a857a2cb080dbc015c59b89acbb195ae7991a99 Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Thu, 11 May 2023 12:54:31 -0700
Subject: [PATCH v6 4/5] Add default_collation_provider GUC.
Controls default collation provider for CREATE COLLATION. Does not
affect CREATE DATABASE, which gets its default from the template
database.
---
doc/src/sgml/config.sgml | 17 +++++++++++++
doc/src/sgml/ref/create_collation.sgml | 15 ++++++++---
src/backend/commands/collationcmds.c | 8 +++++-
src/backend/utils/misc/guc_tables.c | 18 +++++++++++++
src/backend/utils/misc/postgresql.conf.sample | 4 +++
src/include/commands/collationcmds.h | 2 ++
.../regress/expected/collate.icu.utf8.out | 25 +++++++++++++++++++
src/test/regress/sql/collate.icu.utf8.sql | 13 ++++++++++
8 files changed, 97 insertions(+), 5 deletions(-)
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 18ce06729b..58a1046340 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -9820,6 +9820,23 @@ SET XML OPTION { DOCUMENT | CONTENT };
</listitem>
</varlistentry>
+ <varlistentry id="guc-default-collation-provider" xreflabel="default_collation_provider">
+ <term><varname>default_collation_provider</varname> (<type>enum</type>)
+ <indexterm>
+ <primary><varname>default_collation_provider</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Default collation provider for <command>CREATE
+ COLLATION</command>. Does not affect <command>CREATE
+ DATABASE</command>, which gets the default collation provider from the
+ template database. Valid values are <literal>icu</literal> and
+ <literal>libc</literal>. The default is <literal>libc</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-icu-validation-level" xreflabel="icu_validation_level">
<term><varname>icu_validation_level</varname> (<type>enum</type>)
<indexterm>
diff --git a/doc/src/sgml/ref/create_collation.sgml b/doc/src/sgml/ref/create_collation.sgml
index 1ac41831d8..c9b3e6e218 100644
--- a/doc/src/sgml/ref/create_collation.sgml
+++ b/doc/src/sgml/ref/create_collation.sgml
@@ -121,10 +121,17 @@ CREATE COLLATION [ IF NOT EXISTS ] <replaceable>name</replaceable> FROM <replace
<para>
Specifies the provider to use for locale services associated with this
collation. Possible values are <literal>none</literal>,
- <literal>icu</literal><indexterm><primary>ICU</primary></indexterm>
- (if the server was built with ICU support) or <literal>libc</literal>.
- <literal>libc</literal> is the default. See <xref
- linkend="locale-providers"/> for details.
+ <literal>icu</literal><indexterm><primary>ICU</primary></indexterm> (if
+ the server was built with ICU support) or <literal>libc</literal>. See
+ <xref linkend="locale-providers"/> for details.
+ </para>
+ <para>
+ If <replaceable>provider</replaceable> is not specified, and
+ <replaceable>lc_collate</replaceable> or
+ <replaceable>lc_ctype</replaceable> is specified, the
+ <literal>libc</literal> provider is used. Otherwise, the default
+ provider is controlled by <xref
+ linkend="guc-default-collation-provider"/>.
</para>
<para>
If the provider is <literal>icu</literal> and the locale is
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index 21615746f9..25e8d32fd9 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -47,6 +47,7 @@ typedef struct
int enc; /* encoding */
} CollAliasData;
+int default_collation_provider = (int) COLLPROVIDER_LIBC;
/*
* CREATE COLLATION
@@ -228,7 +229,12 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
collproviderstr)));
}
else
- collprovider = COLLPROVIDER_LIBC;
+ {
+ if (lccollateEl || lcctypeEl)
+ collprovider = COLLPROVIDER_LIBC;
+ else
+ collprovider = (char) default_collation_provider;
+ }
if (collprovider == COLLPROVIDER_NONE
&& (localeEl || lccollateEl || lcctypeEl))
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 844781a7f5..901cfda819 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -35,8 +35,10 @@
#include "access/xlogrecovery.h"
#include "archive/archive_module.h"
#include "catalog/namespace.h"
+#include "catalog/pg_collation.h"
#include "catalog/storage.h"
#include "commands/async.h"
+#include "commands/collationcmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/user.h"
@@ -166,6 +168,12 @@ static const struct config_enum_entry intervalstyle_options[] = {
{NULL, 0, false}
};
+static const struct config_enum_entry collation_provider_options[] = {
+ {"icu", (int) 'i', false},
+ {"libc", (int) 'c', false},
+ {NULL, 0, false}
+};
+
static const struct config_enum_entry icu_validation_level_options[] = {
{"disabled", -1, false},
{"debug5", DEBUG5, false},
@@ -4683,6 +4691,16 @@ struct config_enum ConfigureNamesEnum[] =
NULL, NULL, NULL
},
+ {
+ {"default_collation_provider", PGC_USERSET, CLIENT_CONN_LOCALE,
+ gettext_noop("Default collation provider for CREATE COLLATION."),
+ NULL
+ },
+ &default_collation_provider,
+ (int) COLLPROVIDER_LIBC, collation_provider_options,
+ NULL, NULL, NULL
+ },
+
{
{"icu_validation_level", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Log level for reporting invalid ICU locale strings."),
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index c8018da04a..c1f247378d 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -734,6 +734,10 @@
#lc_numeric = 'C' # locale for number formatting
#lc_time = 'C' # locale for time formatting
+#default_collation_provider = 'libc' # default collation provider
+ # for CREATE COLLATION
+ # (none, icu, libc)
+
#icu_validation_level = WARNING # report ICU locale validation
# errors at the given level
diff --git a/src/include/commands/collationcmds.h b/src/include/commands/collationcmds.h
index b76c7b3dc3..f54389525d 100644
--- a/src/include/commands/collationcmds.h
+++ b/src/include/commands/collationcmds.h
@@ -18,6 +18,8 @@
#include "catalog/objectaddress.h"
#include "parser/parse_node.h"
+extern PGDLLIMPORT int default_collation_provider;
+
extern ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists);
extern void IsThereCollationInNamespace(const char *collname, Oid nspOid);
extern ObjectAddress AlterCollation(AlterCollationStmt *stmt);
diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out
index cf1852c89d..ea96e27f45 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -1038,6 +1038,31 @@ RESET client_min_messages;
-- uses "none" provider instead
CREATE COLLATION testc (provider = icu, locale='C');
NOTICE: using locale provider "none" for ICU locale "C"
+SET default_collation_provider = 'libc';
+CREATE COLLATION def_libc (LOCALE = 'C');
+SELECT collname, collprovider FROM pg_collation WHERE collname='def_libc';
+ collname | collprovider
+----------+--------------
+ def_libc | c
+(1 row)
+
+DROP COLLATION def_libc;
+SET default_collation_provider = 'icu';
+CREATE COLLATION def_icu (LOCALE = 'und');
+SELECT collname, collprovider FROM pg_collation WHERE collname='def_icu';
+ collname | collprovider
+----------+--------------
+ def_icu | i
+(1 row)
+
+CREATE COLLATION def_libc (LC_COLLATE = 'C', LC_CTYPE='C');
+SELECT collname, collprovider FROM pg_collation WHERE collname='def_libc';
+ collname | collprovider
+----------+--------------
+ def_libc | c
+(1 row)
+
+RESET default_collation_provider;
CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8'); -- fail, needs "locale"
ERROR: parameter "locale" must be specified
SET icu_validation_level = ERROR;
diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql
index e59200df9a..ee607ca3a5 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -378,6 +378,19 @@ RESET client_min_messages;
-- uses "none" provider instead
CREATE COLLATION testc (provider = icu, locale='C');
+SET default_collation_provider = 'libc';
+CREATE COLLATION def_libc (LOCALE = 'C');
+SELECT collname, collprovider FROM pg_collation WHERE collname='def_libc';
+DROP COLLATION def_libc;
+
+SET default_collation_provider = 'icu';
+CREATE COLLATION def_icu (LOCALE = 'und');
+SELECT collname, collprovider FROM pg_collation WHERE collname='def_icu';
+CREATE COLLATION def_libc (LC_COLLATE = 'C', LC_CTYPE='C');
+SELECT collname, collprovider FROM pg_collation WHERE collname='def_libc';
+
+RESET default_collation_provider;
+
CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8'); -- fail, needs "locale"
SET icu_validation_level = ERROR;
CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere'); -- fails
--
2.34.1