Fix error reporting for SQL/JSON path type mismatches

Amit Langote <amitlan@postgresql.org>

Commit: 15ba0702c1ae9d46f49a6e1f80db99167d3aedf7
Author: Amit Langote <amitlan@postgresql.org>
Date: 2025-11-27T02:59:40Z
Releases: 18.2
Fix error reporting for SQL/JSON path type mismatches

transformJsonFuncExpr() used exprType()/exprLocation() on the
possibly coerced path expression, which could be NULL when
coercion to jsonpath failed, leading to "cache lookup failed
for type 0" errors.

Preserve the original expression node so that type and location
in the "must be of type jsonpath" error are reported correctly.
Add regression tests to cover these cases.

Reported-by: Jian He <jian.universality@gmail.com>
Author: Jian He <jian.universality@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Discussion: https://postgr.es/m/CACJufxHunVg81JMuNo8Yvv_hJD0DicgaVN2Wteu8aJbVJPBjZA@mail.gmail.com
Backpatch-through: 17

Files

Discussion