pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
8+ messages / 4 participants
[nested] [flat]
* BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-08 19:52 xtracoder@gmail.com
0 siblings, 1 reply; 8+ messages in thread
From: xtracoder@gmail.com @ 2016-02-08 19:52 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 13936
Logged by: Xtra Coder
Email address: xtracoder@gmail.com
PostgreSQL version: 9.5.0
Operating system: Windows7
Description:
I'm getting absolutely misleading error message when trying to build a JSON
object from empty resultset.
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.: '{}'
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-09 01:45 Peter Geoghegan <pg@heroku.com>
parent: xtracoder@gmail.com
0 siblings, 1 reply; 8+ messages in thread
From: Peter Geoghegan @ 2016-02-09 01:45 UTC (permalink / raw)
To: xtracoder@gmail.com; +Cc: pgsql-bugs; Andrew Dunstan <andrew@dunslane.net>
On Mon, Feb 8, 2016 at 11:52 AM, <xtracoder@gmail.com> 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:
#0 errfinish (dummy=dummy@entry=0) at elog.c:412
#1 0x00000000007fc11d in elog_finish (elevel=elevel@entry=20,
fmt=fmt@entry=0x9c5c30 "unkno"...) at elog.c:1372
#2 0x000000000076b006 in iteratorFromContainer
(container=container@entry=0x1be0d2c, parent=parent@entry=0x0) at
jsonb_util.c:930
#3 0x000000000076c3b4 in JsonbIteratorInit
(container=container@entry=0x1be0d2c) at jsonb_util.c:719
#4 0x0000000000766ea1 in JsonbToCStringWorker (out=0x1c74780,
out@entry=0x0, in=0x1be0d2c, estimated_len=6, indent=indent@entry=0
'\000') at jsonb.c:471
#5 0x000000000076855c in JsonbToCString (out=out@entry=0x0,
in=<optimized out>, estimated_len=<optimized out>) at jsonb.c:430
#6 0x000000000076857e in jsonb_out (fcinfo=<optimized out>) at jsonb.c:136
#7 0x00000000007fec03 in FunctionCall1Coll
(flinfo=flinfo@entry=0x1c6d0f0, collation=collation@entry=0,
arg1=arg1@entry=29232424) at fmgr.c:1297
#8 0x000000000080015f in OutputFunctionCall (flinfo=0x1c6d0f0,
val=29232424) at fmgr.c:1950
#9 0x000000000047294d in (slot=0x1c6c650, self=0x1be13c0) at printtup.c:359
--
Peter Geoghegan
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-09 11:57 Michael Paquier <michael.paquier@gmail.com>
parent: Peter Geoghegan <pg@heroku.com>
0 siblings, 2 replies; 8+ messages in thread
From: Michael Paquier @ 2016-02-09 11:57 UTC (permalink / raw)
To: Peter Geoghegan <pg@heroku.com>; +Cc: pgsql-bugs; Andrew Dunstan <andrew@dunslane.net>
On Tue, Feb 9, 2016 at 10:45 AM, Peter Geoghegan <pg@heroku.com> wrote:
> On Mon, Feb 8, 2016 at 11:52 AM, <xtracoder@gmail.com> 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.
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,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
jsonb-objs-empty.patch (text/x-patch, 2.8K) download
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index 9151a13..f7138a6 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -1455,7 +1455,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
errmsg("wrong number of array subscripts")));
if (nkdims == 0)
- PG_RETURN_DATUM(CStringGetTextDatum("{}"));
+ PG_RETURN_DATUM(jsonb_from_cstring("{}", 2));
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
diff --git a/src/test/regress/expected/json.out b/src/test/regress/expected/json.out
index 0ced17e..502f983 100644
--- a/src/test/regress/expected/json.out
+++ b/src/test/regress/expected/json.out
@@ -1510,6 +1510,20 @@ INSERT INTO foo VALUES (999999, NULL, 'bar');
SELECT json_object_agg(name, type) FROM foo;
ERROR: field name must not be null
-- json_object
+-- empty object, one dimension
+SELECT json_object('{}');
+ json_object
+-------------
+ {}
+(1 row)
+
+-- empty object, two dimensions
+SELECT json_object('{}', '{}');
+ json_object
+-------------
+ {}
+(1 row)
+
-- one dimension
SELECT json_object('{a,1,b,2,3,NULL,"d e f","a b c"}');
json_object
diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/jsonb.out
index 72fe808..4789e4e 100644
--- a/src/test/regress/expected/jsonb.out
+++ b/src/test/regress/expected/jsonb.out
@@ -1410,6 +1410,20 @@ INSERT INTO foo VALUES (999999, NULL, 'bar');
SELECT jsonb_object_agg(name, type) FROM foo;
ERROR: field name must not be null
-- jsonb_object
+-- empty object, one dimension
+SELECT jsonb_object('{}');
+ jsonb_object
+--------------
+ {}
+(1 row)
+
+-- empty object, two dimensions
+SELECT jsonb_object('{}', '{}');
+ jsonb_object
+--------------
+ {}
+(1 row)
+
-- one dimension
SELECT jsonb_object('{a,1,b,2,3,NULL,"d e f","a b c"}');
jsonb_object
diff --git a/src/test/regress/sql/json.sql b/src/test/regress/sql/json.sql
index 0d2c139..39f1b70 100644
--- a/src/test/regress/sql/json.sql
+++ b/src/test/regress/sql/json.sql
@@ -462,6 +462,12 @@ SELECT json_object_agg(name, type) FROM foo;
-- json_object
+-- empty object, one dimension
+SELECT json_object('{}');
+
+-- empty object, two dimensions
+SELECT json_object('{}', '{}');
+
-- one dimension
SELECT json_object('{a,1,b,2,3,NULL,"d e f","a b c"}');
diff --git a/src/test/regress/sql/jsonb.sql b/src/test/regress/sql/jsonb.sql
index b724f0a..4b24477 100644
--- a/src/test/regress/sql/jsonb.sql
+++ b/src/test/regress/sql/jsonb.sql
@@ -352,6 +352,12 @@ SELECT jsonb_object_agg(name, type) FROM foo;
-- jsonb_object
+-- empty object, one dimension
+SELECT jsonb_object('{}');
+
+-- empty object, two dimensions
+SELECT jsonb_object('{}', '{}');
+
-- one dimension
SELECT jsonb_object('{a,1,b,2,3,NULL,"d e f","a b c"}');
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-09 14:37 Andrew Dunstan <andrew@dunslane.net>
parent: Michael Paquier <michael.paquier@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Andrew Dunstan @ 2016-02-09 14:37 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; Peter Geoghegan <pg@heroku.com>; +Cc: pgsql-bugs
On 02/09/2016 06:57 AM, Michael Paquier wrote:
> On Tue, Feb 9, 2016 at 10:45 AM, Peter Geoghegan <pg@heroku.com> wrote:
>> On Mon, Feb 8, 2016 at 11:52 AM, <xtracoder@gmail.com> 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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-10 00:07 Michael Paquier <michael.paquier@gmail.com>
parent: Andrew Dunstan <andrew@dunslane.net>
0 siblings, 1 reply; 8+ messages in thread
From: Michael Paquier @ 2016-02-10 00:07 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: Peter Geoghegan <pg@heroku.com>; pgsql-bugs
On Tue, Feb 9, 2016 at 11:37 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
> On 02/09/2016 06:57 AM, Michael Paquier wrote:
>> 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.
OK, good to know. Feel free to ping me if you need some extra hands,
though I don't think you will actually need them :)
> I'll get it done.
Thanks.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-12 02:39 Michael Paquier <michael.paquier@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Paquier @ 2016-02-12 02:39 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: Peter Geoghegan <pg@heroku.com>; pgsql-bugs
On Wed, Feb 10, 2016 at 9:07 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Tue, Feb 9, 2016 at 11:37 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
>> On 02/09/2016 06:57 AM, Michael Paquier wrote:
>>> 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.
>
> OK, good to know. Feel free to ping me if you need some extra hands,
> though I don't think you will actually need them :)
Entry in next CF to not get that lost is here:
https://commitfest.postgresql.org/9/515/
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-21 15:46 Andrew Dunstan <andrew@dunslane.net>
parent: Michael Paquier <michael.paquier@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Andrew Dunstan @ 2016-02-21 15:46 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; Peter Geoghegan <pg@heroku.com>; +Cc: pgsql-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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container
@ 2016-02-22 00:03 Michael Paquier <michael.paquier@gmail.com>
parent: Andrew Dunstan <andrew@dunslane.net>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Paquier @ 2016-02-22 00:03 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: Peter Geoghegan <pg@heroku.com>; pgsql-bugs
On Mon, Feb 22, 2016 at 12:46 AM, Andrew Dunstan <andrew@dunslane.net> wrote:
> 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.
Thanks. I have hesitated with your solution, looks like I was on the
wrong side at the end :)
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2016-02-22 00:03 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-02-08 19:52 BUG #13936: jsonb_object() -> ERROR: unknown type of jsonb container xtracoder@gmail.com
2016-02-09 01:45 ` Peter Geoghegan <pg@heroku.com>
2016-02-09 11:57 ` Michael Paquier <michael.paquier@gmail.com>
2016-02-09 14:37 ` Andrew Dunstan <andrew@dunslane.net>
2016-02-10 00:07 ` Michael Paquier <michael.paquier@gmail.com>
2016-02-12 02:39 ` Michael Paquier <michael.paquier@gmail.com>
2016-02-21 15:46 ` Andrew Dunstan <andrew@dunslane.net>
2016-02-22 00:03 ` Michael Paquier <michael.paquier@gmail.com>
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