Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aXWDO-0008NM-Fi for pgsql-bugs@arkaria.postgresql.org; Sun, 21 Feb 2016 15:46:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aXWDO-0007sQ-2c for pgsql-bugs@arkaria.postgresql.org; Sun, 21 Feb 2016 15:46:30 +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 1aXWDN-0007sJ-PJ for pgsql-bugs@postgresql.org; Sun, 21 Feb 2016 15:46:29 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aXWDH-0007IQ-V7 for pgsql-bugs@postgresql.org; Sun, 21 Feb 2016 15:46:26 +0000 Received: from mfilter44-d.gandi.net (mfilter44-d.gandi.net [217.70.178.175]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 77F041720A1; Sun, 21 Feb 2016 16:46:22 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter44-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter44-d.gandi.net (mfilter44-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 8Zn48w5quTGB; Sun, 21 Feb 2016 16:46:21 +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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 213C4172094; Sun, 21 Feb 2016 16:46:19 +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: <56C9DBCA.1070804@dunslane.net> Date: Sun, 21 Feb 2016 10:46:18 -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: > > 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