From: Kouhei Sutou <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
Date: Fri, 01 Jan 2016 18:14:28 +0900 (JST)
Message-ID: <20160101.181428.648571074852937725.kou@clear-code.com> (raw)
In-Reply-To: <20151231153522.1117.56276@wrigleys.postgresql.org>
References: <20151231153522.1117.56276@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:0001-Support-dumping-string-index-parameters-of-amindex-e.patch (text/x-patch, 2.8K) download
From b96f59cca4d2f172c579185add9516c18054aff0 Mon Sep 17 00:00:00 2001
From: Kouhei Sutou <kou@clear-code.com>
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.cindex 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: kou@clear-code.com
Subject: Re: BUG #13840: pg_dump generates unloadable SQL when third party string type index option is used
In-Reply-To: <20160101.181428.648571074852937725.kou@clear-code.com>
References: <20151231153522.1117.56276@wrigleys.postgresql.org> <20160101.181428.648571074852937725.kou@clear-code.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox