0001-Add-CREATE-COLLATION-auto_comment-option.patch

text/plain

Filename: 0001-Add-CREATE-COLLATION-auto_comment-option.patch
Type: text/plain
Part: 0
Message: Re: Crash report for some ICU-52 (debian8) COLLATE and work_mem values

Patch

Format: format-patch
Series: patch 0001
Subject: Add CREATE COLLATION auto_comment option
File+
src/backend/commands/collationcmds.c 24 0
From ca6c6e4c7a42eb02ddf3e9e6e1669f433b72f77b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Mon, 14 Aug 2017 13:18:57 -0400
Subject: [RFC PATCH] Add CREATE COLLATION auto_comment option

---
 src/backend/commands/collationcmds.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index 96a6bc9bf0..d5a4dcbdbd 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -37,6 +37,11 @@
 #include "utils/syscache.h"
 
 
+#ifdef USE_ICU
+static char *get_icu_locale_comment(const char *localename);
+#endif
+
+
 typedef struct
 {
 	char	   *localename;		/* name of locale, as per "locale -a" */
@@ -56,11 +61,13 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
 	AclResult	aclresult;
 	ListCell   *pl;
 	DefElem    *fromEl = NULL;
+	DefElem	   *autocommentEl = NULL;
 	DefElem    *localeEl = NULL;
 	DefElem    *lccollateEl = NULL;
 	DefElem    *lcctypeEl = NULL;
 	DefElem    *providerEl = NULL;
 	DefElem    *versionEl = NULL;
+	bool		autocomment = false;
 	char	   *collcollate = NULL;
 	char	   *collctype = NULL;
 	char	   *collproviderstr = NULL;
@@ -84,6 +91,8 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
 
 		if (pg_strcasecmp(defel->defname, "from") == 0)
 			defelp = &fromEl;
+		else if (pg_strcasecmp(defel->defname, "auto_comment") == 0)
+			defelp = &autocommentEl;
 		else if (pg_strcasecmp(defel->defname, "locale") == 0)
 			defelp = &localeEl;
 		else if (pg_strcasecmp(defel->defname, "lc_collate") == 0)
@@ -143,6 +152,9 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
 					 errmsg("collation \"default\" cannot be copied")));
 	}
 
+	if (autocommentEl)
+		autocomment = defGetBoolean(autocommentEl);
+
 	if (localeEl)
 	{
 		collcollate = defGetString(localeEl);
@@ -224,6 +236,18 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
 
 	ObjectAddressSet(address, CollationRelationId, newoid);
 
+#ifdef USE_ICU
+	if (autocomment && collprovider == COLLPROVIDER_ICU)
+	{
+		char	   *icucomment;
+
+		icucomment = get_icu_locale_comment(collcollate);
+		if (icucomment)
+			CreateComments(newoid, CollationRelationId, 0,
+						   icucomment);
+	}
+#endif
+
 	return address;
 }
 

base-commit: ea0ca75d5d14e0c98782a2188405685af4a475a0
-- 
2.14.1