Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aEvnO-0003C2-2X for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Jan 2016 09:14:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aEvnM-0008D3-7k for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Jan 2016 09:14:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aEvnK-0008Cu-OU for pgsql-bugs@postgresql.org; Fri, 01 Jan 2016 09:14:46 +0000 Received: from mail.clear-code.com ([219.94.234.64]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aEvnA-0006ou-S3 for pgsql-bugs@postgresql.org; Fri, 01 Jan 2016 09:14:45 +0000 Received: from localhost (42-146-88-165.rev.home.ne.jp [42.146.88.165]) by mail.clear-code.com (Postfix) with ESMTPSA id 57608E84FA for ; Fri, 1 Jan 2016 18:14:31 +0900 (JST) Date: Fri, 01 Jan 2016 18:14:28 +0900 (JST) Message-Id: <20160101.181428.648571074852937725.kou@clear-code.com> To: pgsql-bugs@postgresql.org Subject: Re: BUG #13840: pg_dump generates unloadable SQL when third party string type index option is used From: Kouhei Sutou In-Reply-To: <20151231153522.1117.56276@wrigleys.postgresql.org> References: <20151231153522.1117.56276@wrigleys.postgresql.org> X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Fri_Jan__1_18_14_28_2016_261)--" Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ----Next_Part(Fri_Jan__1_18_14_28_2016_261)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, In <20151231153522.1117.56276@wrigleys.postgresql.org> "[BUGS] BUG #13840: pg_dump generates unloadable SQL when third party string type index option is used" on Thu, 31 Dec 2015 15:35:22 +0000, kou@clear-code.com wrote: > Bug reference: 13840 > Logged by: Kouhei Sutou > Email address: kou@clear-code.com > PostgreSQL version: 9.4.5 > Operating system: Debian GNU/Linux sid > Description: ... > pg_dump generates "CREATE INDEX ... WITH ..." without quotation for > option value: > > % pg_dump -d option_test > ... > CREATE TABLE t ( > c text > ); > ... > CREATE INDEX pgroonga_index ON t USING pgroonga (c) WITH (normalizer=none); > ... > > "normalizer=none" causes error on restoring the dump. > > pg_dump should generates "normalizer='none'" as option to avoid the > error. I attach a patch. With this patch, pg_dump generates string index option value with quote like the following: CREATE INDEX pgrn_index ON memos USING pgroonga (title) WITH (normalizer='none'); Thanks, -- kou ----Next_Part(Fri_Jan__1_18_14_28_2016_261)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-Support-dumping-string-index-parameters-of-amindex-e.patch" From b96f59cca4d2f172c579185add9516c18054aff0 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Fri, 1 Jan 2016 16:54:50 +0900 Subject: [PATCH] Support dumping string index parameters of amindex extension BUG #13840 pg_dump dumps string index parameters of amindex extension without quote like: CREATE INDEX pgroonga_index ON t USING pgroonga (c) WITH (normalizer=none); "normalizer=none" is syntax error because "none" isn't one of the reserved keywords. pg_dump should dump "none" with quote like: CREATE INDEX pgroonga_index ON t USING pgroonga (c) WITH (normalizer='none'); This change quotes index parameter value when the value may be a string value. --- src/backend/utils/adt/ruleutils.c | 63 ++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 280808a..e9ece0f 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -56,6 +56,7 @@ #include "utils/array.h" #include "utils/builtins.h" #include "utils/fmgroids.h" +#include "utils/guc.h" #include "utils/hsearch.h" #include "utils/lsyscache.h" #include "utils/rel.h" @@ -9858,18 +9859,58 @@ flatten_reloptions(Oid relid) Anum_pg_class_reloptions, &isnull); if (!isnull) { - Datum sep, - txt; + StringInfoData buf; + Datum *options; + int i; + int noptions; - /* - * We want to use array_to_text(reloptions, ', ') --- but - * DirectFunctionCall2(array_to_text) does not work, because - * array_to_text() relies on flinfo to be valid. So use - * OidFunctionCall2. - */ - sep = CStringGetTextDatum(", "); - txt = OidFunctionCall2(F_ARRAY_TO_TEXT, reloptions, sep); - result = TextDatumGetCString(txt); + initStringInfo(&buf); + + deconstruct_array(DatumGetArrayTypeP(reloptions), + TEXTOID, -1, false, 'i', + &options, NULL, &noptions); + + for (i = 0; i < noptions; i++) + { + char *option; + char *name; + char *separator; + char *value; + + option = TextDatumGetCString(options[i]); + name = option; + separator = strchr(name, '='); + *separator = '\0'; + value = separator + 1; + + if (i > 0) + appendStringInfoString(&buf, ", "); + + appendStringInfo(&buf, "%s=", name); + if (parse_bool(value, NULL) || + parse_int(value, NULL, 0, NULL) || + parse_real(value, NULL)) + { + appendStringInfoString(&buf, value); + } + else + { + char *v; + appendStringInfoString(&buf, "'"); + for (v = value; *v != '\0'; v++) + { + if (*v == '\'') + appendStringInfo(&buf, "'%c", *v); + else + appendStringInfo(&buf, "%c", *v); + } + appendStringInfoString(&buf, "'"); + } + + pfree(option); + } + + result = buf.data; } ReleaseSysCache(tuple); -- 2.6.4 ----Next_Part(Fri_Jan__1_18_14_28_2016_261)-- Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ----Next_Part(Fri_Jan__1_18_14_28_2016_261)----