Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aT9Qs-0006Zy-F5 for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 14:38:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aT9Qs-0001eA-1o for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 14:38:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aT9Qr-0001dw-Gz for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 14:38:21 +0000 Received: from relay2-d.mail.gandi.net ([2001:4b98:c:538::194]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aT9Qo-0004Dw-T4 for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 14:38:20 +0000 Received: from mfilter29-d.gandi.net (mfilter29-d.gandi.net [217.70.178.160]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id E08FCC5A73; Tue, 9 Feb 2016 15:38:15 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter29-d.gandi.net Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter29-d.gandi.net (mfilter29-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 7fIuEyLWlRfl; Tue, 9 Feb 2016 15:37:43 +0100 (CET) X-Originating-IP: 98.122.164.227 Received: from [192.168.10.146] (unknown [98.122.164.227]) (Authenticated sender: adsend@dunslane.net) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id AC0A6C5A4F; Tue, 9 Feb 2016 15:37:42 +0100 (CET) Subject: Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container To: Michael Paquier , Peter Geoghegan References: <20160208195207.2647.46863@wrigleys.postgresql.org> Cc: xtracoder@gmail.com, pgsql-bugs From: Andrew Dunstan Message-ID: <56B9F9B5.9060409@dunslane.net> Date: Tue, 9 Feb 2016 09:37:41 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed 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 On 02/09/2016 06:57 AM, Michael Paquier wrote: > On Tue, Feb 9, 2016 at 10:45 AM, Peter Geoghegan wrote: >> On Mon, Feb 8, 2016 at 11:52 AM, wrote: >>> Here is the simple code to reproduce: >>> >>> select jsonb_object('{}'::text[], '{}'::text[]) >>> >>> Result of execution is >>> >>> ERROR: unknown type of jsonb container >>> ********** Error ********** >>> >>> ERROR: unknown type of jsonb container >>> SQL state: XX000 >>> >>> Expected result - jsonb object with no attributes, i.e.: '{}' >> I agree that this is a bug. >> >> Looks like it's coming from the jsonb output function, which is an >> additional concern: > 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. Oh. Feeling a bit sheepish right now. > > 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. Yeah, I don't think we need to optimize this case too much. I'll get it done. 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