RE: Inconsistent Behavior in JSONB Numeric Array Deletion

From: "Mark Drake" <mark(dot)drake(at)golden-hind(dot)com>
To: "'David E(dot) Wheeler'" <david(at)justatheory(dot)com>, "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "'Robert Haas'" <robertmhaas(at)gmail(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Inconsistent Behavior in JSONB Numeric Array Deletion
Date: 2025-06-11 23:55:10
Message-ID: 008001dbdb2c$44101430$cc303c90$@golden-hind.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I am certainly not tied to the '-' operator, but I think the ability to remove items from a numeric json array, based on a value would be something that would benefit many users.

-----Original Message-----
From: David E. Wheeler <david(at)justatheory(dot)com>
Sent: Wednesday, June 11, 2025 2:48 PM
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>; Mark Dake <mark(dot)drake(at)golden-hind(dot)com>; pgsql-hackers(at)postgresql(dot)org
Subject: Re: Inconsistent Behavior in JSONB Numeric Array Deletion

On Jun 11, 2025, at 17:43, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> I fear that that would cause some problems. Consider
>
> regression=# select '["foo", "bar"]'::jsonb - 'bar'; ?column?
> ----------
> ["foo"]
> (1 row)
>
> Right now we resolve the unlabeled literal as type text.
> But if jsonb - jsonb existed, we'd decide it's jsonb, thanks to the
> heuristic that prefers same-type-as-the-other-input (rule 2a at [1]).
> So it's pretty nearly certain that adding jsonb - jsonb would break
> some existing queries; or worse, silently cause them to do something
> different.
> Maybe that's acceptable, but it's a demerit of this proposal.

Ah. It’s a pity the existing operator behaves differently for different rhs operands. But maybe add a new one that’s defined to operator on contents rather than keys/indexes and deprecate (or un-document) the content behavior in the `-` operator?

Best,

Davi

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-06-12 02:33:52 Re: Make COPY format extendable: Extract COPY TO format implementations
Previous Message Mark Drake 2025-06-11 23:52:05 RE: Inconsistent Behavior in JSONB Numeric Array Deletion