| From: | "David E(dot) Wheeler" <david(at)justatheory(dot)com> |
|---|---|
| To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
| Cc: | 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 |
| Date: | 2025-06-11 21:18:24 |
| Message-ID: | 01F6F2CF-E293-453D-8AC1-1383F5D33656@justatheory.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Jun 11, 2025, at 16:03, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> The proposed behavior of the operator you want to add would be
> inconsistent with the existing integer subtraction operator, because
> the former would remove by value and the latter removes by index.
Bear in mind that `-` currently does both. Of the three current variants, the first two delete from an array by value:
* jsonb - text: Deletes a key (and its value) from a JSON object, or matching string value(s) from a JSON array.
* jsonb - text[] → jsonb: Deletes all matching keys or array elements from the left operand.
* jsonb - integer → jsonb: Deletes the array element with specified index (negative integers count from the end). Throws an error if JSON value is not an array.
Before I went and looked it up, I was also thinking this could use a different operator. But it’s already a bit overloaded, alas. So I could see the new behavior being:
* jsonb - jsonb → jsonb: Deletes the array element with specified value. Throws an error if JSON value is not an array.
> Now, none of that means that we couldn't define -(jsonb,jsonb) in the
> manner you propose. But that's just a feature idea, not an
> inconsistency.
Agreed. One might also think of it as a “gap to fill”, but it’s a new behavior. In any event, whether the feature uses `-` is a point we can resolve by consensus, given a patch that implements the feature.
Best,
David
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2025-06-11 21:32:35 | Re: CHECKPOINT unlogged data |
| Previous Message | Nathan Bossart | 2025-06-11 21:14:53 | Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward |