From: Andrew Dunstan <andrew@dunslane.net>
To: Michael Paquier <michael.paquier@gmail.com>
To: Peter Geoghegan <pg@heroku.com>
Cc: xtracoder@gmail.com, pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
Date: Sun, 21 Feb 2016 10:46:18 -0500
Message-ID: <56C9DBCA.1070804@dunslane.net> (raw)
In-Reply-To: <CAB7nPqQEiWopsEHdarbn6FbaEG7QTzR9gU82G9Nrr-_yDEy-ZA@mail.gmail.com>
References: <20160208195207.2647.46863@wrigleys.postgresql.org>
<CAM3SWZRkQkmqryAxyCrVw_DTbw=hKV5U3qEiWjkCXBhSiSPSCA@mail.gmail.com>
<CAB7nPqQEiWopsEHdarbn6FbaEG7QTzR9gU82G9Nrr-_yDEy-ZA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 02/09/2016 06:57 AM, Michael Paquier wrote:
>
> Yep, this comes from a copy-paste error in jsonb_object_two_arg from
> json_object_two_arg, caused by this bit particularly:
> if (nkdims == 0)
> PG_RETURN_DATUM(CStringGetTextDatum("{}"));
> json is represented as an equivalent of a text data type, but that's
> not the case of jsonb. So while this will work for json, that's really
> broken for jsonb.
>
> One way to address this issue is to call jsonb_from_cstring() when
> nkdims == 0. Another method, a bit more complex, is to build an empty
> object and then return it as a result, like more or less that for
> example:
> pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL);
> result = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
> return result;
>
> The patch attached uses jsonb_from_cstring(), with new regression
> tests, and it fixes the issue for me. That seems more simple, but the
> other method would work as well, though I am not sure this is worth
> the complication.
> Regards,
I have committed a fix for this, mainly using your patch. In the end I
used the same pattern for handling the case that we use in the
one-argument form of the function, i.e. we just drop through to the end,
skipping over the part where we add object elements.
cheers
andrew
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: andrew@dunslane.net, michael.paquier@gmail.com, pg@heroku.com
Subject: Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
In-Reply-To: <56C9DBCA.1070804@dunslane.net>
References: <20160208195207.2647.46863@wrigleys.postgresql.org> <CAM3SWZRkQkmqryAxyCrVw_DTbw=hKV5U3qEiWjkCXBhSiSPSCA@mail.gmail.com> <CAB7nPqQEiWopsEHdarbn6FbaEG7QTzR9gU82G9Nrr-_yDEy-ZA@mail.gmail.com> <56C9DBCA.1070804@dunslane.net>
* 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