On Fri, Apr 27, 2012 at 11:27:03AM +0200, Vik Reykja wrote:
> On Fri, Apr 27, 2012 at 03:12, Tom Lane <[email protected]> wrote:
>
> > Does anybody else have an opinion as to which of these solutions is
> > more preferable?
> >
>
> I think all unquoted whitespace should be ignored, so I prefer your
> solution. (note: I haven't actually tested it, I'm going off these emails)
As long as we make it consistent on both sides of the '=>' (and document
it, too), then I don't really care either way. Currently you have to use
quotes to get an empty key, so I thought it natural to that you should
have to quote to get an empty value.
I've attached a modified version of Tom's patch which also allows empty
keys.
>
>
> > And should we regard this as a back-patchable bug
> > fix, or a definition change suitable only for HEAD?
> >
>
> Since this is removing a syntax error and not creating one, I'd say it
> should be safe to backpatch.
-Ryan Kelly
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index 0eb48cf..f03dcdc 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -74,7 +74,15 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped)
}
else if (*(state->ptr) == '=' && !ignoreeq)
{
- elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin));
+ /* Empty key is perfectly OK */
+ state->ptr--;
+ return true;
+ }
+ else if (*(state->ptr) == ',' && ignoreeq)
+ {
+ /* Empty value is perfectly OK */
+ state->ptr--;
+ return true;
}
else if (*(state->ptr) == '\\')
{
@@ -191,7 +199,7 @@ parse_hstore(HSParser *state)
if (st == WKEY)
{
if (!get_val(state, false, &escaped))
- return;
+ return; /* end of string */
if (state->pcur >= state->plen)
{
state->plen *= 2;
@@ -236,7 +244,10 @@ parse_hstore(HSParser *state)
else if (st == WVAL)
{
if (!get_val(state, true, &escaped))
- elog(ERROR, "Unexpected end of string");
+ {
+ /* end of string, treat as empty value */
+ state->ptr--;
+ }
state->pairs[state->pcur].val = state->word;
state->pairs[state->pcur].vallen = hstoreCheckValLen(state->cur - state->word);
state->pairs[state->pcur].isnull = false;
--
Sent via pgsql-bugs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs