aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r--src/backend/utils/adt/jsonfuncs.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 6c16a953dd3..5fabef0de96 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -726,6 +726,13 @@ get_path_all(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
deconstruct_array(path, TEXTOID, -1, false, 'i',
&pathtext, &pathnulls, &npath);
+ /*
+ * If the array is empty, return NULL; this is dubious but it's what 9.3
+ * did.
+ */
+ if (npath <= 0)
+ PG_RETURN_NULL();
+
tpath = palloc(npath * sizeof(char *));
ipath = palloc(npath * sizeof(int));
@@ -1100,11 +1107,11 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
{
Jsonb *jb = PG_GETARG_JSONB(0);
ArrayType *path = PG_GETARG_ARRAYTYPE_P(1);
+ Jsonb *res;
Datum *pathtext;
bool *pathnulls;
int npath;
int i;
- Jsonb *res;
bool have_object = false,
have_array = false;
JsonbValue *jbvp = NULL;
@@ -1120,6 +1127,13 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
deconstruct_array(path, TEXTOID, -1, false, 'i',
&pathtext, &pathnulls, &npath);
+ /*
+ * If the array is empty, return NULL; this is dubious but it's what 9.3
+ * did.
+ */
+ if (npath <= 0)
+ PG_RETURN_NULL();
+
if (JB_ROOT_IS_OBJECT(jb))
have_object = true;
else if (JB_ROOT_IS_ARRAY(jb) && !JB_ROOT_IS_SCALAR(jb))