| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com> |
| Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, pavel(dot)stehule(at)gmail(dot)com |
| Subject: | Re: jsonb subscripting vs SQL/JSON array accessor semantics (SQL:2023) |
| Date: | 2026-02-10 03:05:07 |
| Message-ID: | CACJufxFWcaAywvJeP4eH2k0si1T-gCth4NmCzxvYHAaUd2Li6g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, Feb 10, 2026 at 5:16 AM Alexandra Wang
<alexandra(dot)wang(dot)oss(at)gmail(dot)com> wrote:
>
> The attached patches implement exactly this:
>
> 0001: Add numeric type support with truncation
Subject: [PATCH v1 1/2] Support numeric type for jsonb subscripting
Previously, using a numeric value as a jsonb subscript would error.
Now numeric subscripts are accepted and truncated toward zero to
produce an integer index. This matches the semantics of array access
in json_query() per the SQL/JSON standard.
Examples:
SELECT ('["a","b","c"]'::jsonb)[1.7]; -- returns "b" (truncates to 1)
SELECT ('["a","b","c"]'::jsonb)[-1.7]; -- returns "c" (truncates to
first thing come to my mind would be special numeric value +inf, -inf, NaN
SELECT ('{"NaN":"b"}'::jsonb)['inf'::numeric];
ERROR: cannot convert infinity to integer
SELECT ('{"NaN":"b"}'::jsonb)['NaN'::numeric];
ERROR: cannot convert NaN to integer
Is the above what we expected, or should just return NULL?
Anyway, obviously we need to test these special numeric values.
+select ('[1, "2", null]'::jsonb)[1.5::float8]; -- errors
+ERROR: subscript type double precision is not supported
+LINE 1: select ('[1, "2", null]'::jsonb)[1.5::float8];
+ ^
+HINT: jsonb subscript must be coercible to either numeric or text.
This errhint message appears to be incorrect?
given that 1.5::float8 is coercible to numeric.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-02-10 03:26:36 | Re: recovery.signal not cleaned up when both signal files are present |
| Previous Message | Richard Guo | 2026-02-10 02:07:16 | Re: Optimize IS DISTINCT FROM with non-nullable inputs |