Re: BUG #18809: Inconsistent JSON behavoir - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #18809: Inconsistent JSON behavoir
Date
Msg-id 3530348.1739426798@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #18809: Inconsistent JSON behavoir  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Wednesday, February 12, 2025, PG Bug reporting form <
> noreply@postgresql.org> wrote:
>> broadway=# select jsonb('[2,3,1]') - to_jsonb(1);
>> ERROR:  operator does not exist: jsonb - jsonb
>> LINE 1: select jsonb('[2,3,1]') - to_jsonb(1);

> This would be a feature request, not a bug report.

Indeed.  We have these cases today:

postgres=# \do -
                                                                 List of operators
   Schema   | Name |        Left arg type        |       Right arg type        |         Result type         |
  Description              

------------+------+-----------------------------+-----------------------------+-----------------------------+-------------------------------------
...
 pg_catalog | -    | jsonb                       | integer                     | jsonb                       | delete
arrayelement 
 pg_catalog | -    | jsonb                       | text                        | jsonb                       | delete
objectfield 
 pg_catalog | -    | jsonb                       | text[]                      | jsonb                       | delete
objectfields 
...

These are already less than consistent, for example this is allowed:

postgres=# select jsonb('[2,3,1]') - 'foo'::text;
 ?column?
-----------
 [2, 3, 1]
(1 row)

but this not so much:

postgres=# select jsonb('{"a": 1, "b": 2}') - 1;
ERROR:  cannot delete from object using integer index

To invent jsonb - jsonb, you'd need to define its behavior for
every possible JSON structure on each side.  I foresee plenty of
bikeshedding.

            regards, tom lane



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #18809: Inconsistent JSON behavoir
Next
From: Tender Wang
Date:
Subject: Re: BUG #18806: When enable_rartitionwise_join is set to ON, the database shuts down abnormally