From: Leo Gaspard <leo@gaspard.io>
To: pgsql-bugs@lists.postgresql.org
Subject: jsonb numerics are treated as arrays
Date: Wed, 17 Jan 2024 19:53:01 +0100
Message-ID: <87h6jbbxma.fsf@coegni.ekleog.org> (raw)
Hey!
A short transcript is better than a thousand words: on PostgreSQL 16.1,
I'm getting:
```
postgres=> SELECT ('42'::jsonb)->0, ('42'::jsonb)->(-1);
?column? | ?column?
----------+----------
42 | 42
(1 row)
```
Dereferencing them with `1` or `-2` returns null as expected, indicating
that jsonb numerics are currently being handled as one-element arrays.
Considering the documentation[1] and especially the note there, I'd have
expected numerics dereferencing to result in `NULL`, because they are
not actually arrays.
[1] https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSON-PROCESSING
TBH, considering this behavior has been present since PostgreSQL 14 at
least, I'd guess it's probably something that can no longer change and
will need to just be documented as being the current behavior.
But I still wanted to raise this on the bugs mailing list, before
sending it to the docs mailing list, because maybe it's behavior that
could still be subject to change?
I'll let you do as you wish, and will work around the issue myself by
checking for jsonb_typeof before dereferencing with 0 or -1 :)
Anyway, thank you for all you do on postgresql, it's a real pleasure to
use! :D
Léo
PS: FWIW, this issue was discovered by the fuzzers for my library when I
left them running overnight, comparing the postgresql backend with a
"completely in-memory" equivalent model.
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: leo@gaspard.io, pgsql-bugs@lists.postgresql.org
Subject: Re: jsonb numerics are treated as arrays
In-Reply-To: <87h6jbbxma.fsf@coegni.ekleog.org>
* 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