Re: BUG #19957: jsonpath `last` returns the wrong index after a filter containing `exists($x[0])`

From: Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: e1638616(at)u(dot)nus(dot)edu, 9erthalion6(at)gmail(dot)com
Subject: Re: BUG #19957: jsonpath `last` returns the wrong index after a filter containing `exists($x[0])`
Date: 2026-12-01 05:19:57
Message-ID: CA+Y2Bme+i2u6c7P+FGMUQp7Lw_3Yfk_vTVN9VPRghZaRvfMtew@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Zsolt, Dmitry,

Thanks both. Zsolt, you're right: the subscript loop also runs the
path items that follow the subscript, so a LAST in a filter there sees
the nested array's size. v2 uses your getArrayIndex() change. It
fixes your two queries and the reported one, and the two exits that
skipped the restore no longer matter, as the loop doesn't change the
context at all.

Dmitry, that also gives the pattern you described (set, one call,
reset) in getArrayIndex(), so I went with it instead of moving the loop
into its own function.

v2 attached. It adds your two queries to the tests, both of which
return [30] now, keeps the three from v1, and changes no existing
expected output. It applies to master and REL_19_STABLE, and make
check passes on both.

Regards,
Ishjaap Singh

Attachment Content-Type Size
v2-0001-Fix-jsonpath-LAST-taking-the-size-of-the-wrong-ar.patch application/octet-stream 6.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Kirill Reshke 2026-12-01 05:38:33 Re: BUG #19846: dump/restore marks inherited NOT VALID not-null constraint as local
Previous Message Michael Paquier 2026-12-01 04:56:28 Re: SIMILAR TO expressions translate wildcards where they shouldn't