pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18809: Inconsistent JSON behavoir
3+ messages / 3 participants
[nested] [flat]

* BUG #18809: Inconsistent JSON behavoir
@ 2025-02-13 03:22  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2025-02-13 03:22 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: mark.drake@golden-hind.com

The following bug has been logged on the website:

Bug reference:      18809
Logged by:          Mark Drake
Email address:      mark.drake@golden-hind.com
PostgreSQL version: 17.0
Operating system:   Linux
Description:        

broadway=# select jsonb('[2,3,1]') @> to_jsonb(1);
 ?column?
----------
 t
(1 row)


broadway=# select jsonb('[2,3,1]') @> to_jsonb(4);
 ?column?
----------
 f
(1 row)


broadway=# select jsonb('[2,3,1]') @> to_jsonb(4);
 ?column?
----------
 f
(1 row)


broadway=# select jsonb('[2,3,1]') - 1;
 ?column?
----------
 [2, 1]
(1 row)


broadway=#
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);
                                ^
HINT:  No operator matches the given name and argument types. You might need
to add explicit type casts.
broadway=#

Given that the first statement show the array contains an element that
matches to_jsonb(1) the fourth statement should delete the third ( index 2)
item from the array, not return an argument type mismatch. This would solve
the problem of not being able to delete from a JSON integer array by value



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #18809: Inconsistent JSON behavoir
@ 2025-02-13 05:24  David G. Johnston <david.g.johnston@gmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2025-02-13 05:24 UTC (permalink / raw)
  To: mark.drake@golden-hind.com <mark.drake@golden-hind.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

On Wednesday, February 12, 2025, PG Bug reporting form <
noreply@postgresql.org> wrote:

> The following bug has been logged on the website:
>
> Bug reference:      18809
> Logged by:          Mark Drake
> Email address:      mark.drake@golden-hind.com
> PostgreSQL version: 17.0
> Operating system:   Linux
> Description:
>
> broadway=#
> 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);
>                                 ^
> HINT:  No operator matches the given name and argument types. You might
> need
> to add explicit type casts.
> broadway=#
>
> Given that the first statement show the array contains an element that
> matches to_jsonb(1) the fourth statement should delete the third ( index 2)
> item from the array, not return an argument type mismatch. This would solve
> the problem of not being able to delete from a JSON integer array by value
>
>
This would be a feature request, not a bug report.

Feature requests usually are better sent to the -general mailing list where
support and possible developers are more likely to be looking.

I do concur we seem to have a feature gap here.

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #18809: Inconsistent JSON behavoir
@ 2025-02-13 06:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2025-02-13 06:06 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: mark.drake@golden-hind.com <mark.drake@golden-hind.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

"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 array element
 pg_catalog | -    | jsonb                       | text                        | jsonb                       | delete object field
 pg_catalog | -    | jsonb                       | text[]                      | jsonb                       | delete object fields
...

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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-02-13 06:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-13 03:22 BUG #18809: Inconsistent JSON behavoir PG Bug reporting form <noreply@postgresql.org>
2025-02-13 05:24 ` David G. Johnston <david.g.johnston@gmail.com>
2025-02-13 06:06   ` Tom Lane <tgl@sss.pgh.pa.us>

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