aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonpath_exec.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2023-01-12 18:16:34 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2023-01-12 18:19:19 +0300
commit9e24e4781750ca92a0a5ff0aaa8e2091785c3bed (patch)
treeb98e97613fe5551722c26f004854e22bb5b4e177 /src/backend/utils/adt/jsonpath_exec.c
parentc0ee6943ca1ded4b1a09be5832ef6e6bc257fb13 (diff)
downloadpostgresql-9e24e4781750ca92a0a5ff0aaa8e2091785c3bed.tar.gz
postgresql-9e24e4781750ca92a0a5ff0aaa8e2091785c3bed.zip
Fix jsonpath existense checking of missing variables
The current jsonpath code assumes that the referenced variable always exists. It could only throw an error at the value valuation time. At the same time existence checking assumes variable is present without valuation, and error suppression doesn't work for missing variables. This commit makes existense checking trigger an error for missing variables. This makes the overall behavior consistent. Backpatch to 12 where jsonpath was introduced. Reported-by: David G. Johnston Discussion: https://postgr.es/m/CAKFQuwbeytffJkVnEqDyLZ%3DrQsznoTh1OgDoOF3VmOMkxcTMjA%40mail.gmail.com Author: Alexander Korotkov, David G. Johnston Backpatch-through: 12
Diffstat (limited to 'src/backend/utils/adt/jsonpath_exec.c')
-rw-r--r--src/backend/utils/adt/jsonpath_exec.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c
index a557ed1ce1e..37b08f1742a 100644
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -891,9 +891,13 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
JsonbValue *v;
bool hasNext = jspGetNext(jsp, &elem);
- if (!hasNext && !found)
+ if (!hasNext && !found && jsp->type != jpiVariable)
{
- res = jperOk; /* skip evaluation */
+ /*
+ * Skip evaluation, but not for variables. We must
+ * trigger an error for the missing variable.
+ */
+ res = jperOk;
break;
}