Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQBSe-00H6qa-M1 for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jan 2024 19:20:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rQBSd-00F8OO-Mk for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jan 2024 19:20:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQB2G-00F3o4-SQ for pgsql-bugs@lists.postgresql.org; Wed, 17 Jan 2024 18:53:12 +0000 Received: from mx1.polytechnique.org ([129.104.30.34]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQB28-002Kvc-Th for pgsql-bugs@lists.postgresql.org; Wed, 17 Jan 2024 18:53:11 +0000 Received: from grym (grym.ekleog.org [94.23.42.210]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id 9AB445612A5 for ; Wed, 17 Jan 2024 19:53:02 +0100 (CET) Received: by smtp.gaspard.ninja (OpenSMTPD) with ESMTP id f1fa3773 for ; Wed, 17 Jan 2024 18:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gaspard.io; h=from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=grym-20170528; bh=8GwxI8ZxItMFYedJ c/85dOuZ60E=; b=mEFFePcllFvaODUmoiHEi9dUeQQ/QZ1s+MUD5kaJ/VSqtF1U Gkp6X68zct/G0MgxB+MhhRI6eiKMNWkYuo+p4Elh7OMSlcNIegbQ4yG5Swd7FzQ4 kb5DPAxNuUa8INZAJ3QfiY6VtU9FFIsD1DhR2CCl/rRA4syaQNVgZD9oqeI= Received: by smtp.gaspard.ninja (OpenSMTPD) with ESMTPS id c7fb4d3a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 17 Jan 2024 18:53:02 +0000 (UTC) Received: from localhost (coegni [local]) by coegni (OpenSMTPD) with ESMTPA id 89264e38 for ; Wed, 17 Jan 2024 18:53:01 +0000 (UTC) From: Leo Gaspard 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Wed Jan 17 19:53:02 2024 +0100 (CET)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.300566, queueID=CEF2C5612AA X-Org-Mail: leo.gaspard.2014@polytechnique.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hey! A short transcript is better than a thousand words: on PostgreSQL 16.1, I'm getting: ``` postgres=3D> 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-J= SON-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=C3=A9o 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.