{
JsonbValue v;
JsonbIteratorToken r;
- JsonbValue *res = NULL;
+ JsonbValue *res;
check_stack_depth();
if (path_nulls[level])
- elog(ERROR, "path element at the position %d is NULL", level + 1);
+ ereport(ERROR,
+ (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
+ errmsg("path element at position %d is null",
+ level + 1)));
r = JsonbIteratorNext(it, &v, false);
r = JsonbIteratorNext(it, &v, false);
Assert(r == WJB_END_ARRAY);
res = pushJsonbValue(st, r, NULL);
-
break;
case WJB_BEGIN_OBJECT:
(void) pushJsonbValue(st, r, NULL);
r = JsonbIteratorNext(it, &v, true);
Assert(r == WJB_END_OBJECT);
res = pushJsonbValue(st, r, NULL);
-
break;
case WJB_ELEM:
case WJB_VALUE:
res = pushJsonbValue(st, r, &v);
break;
default:
- elog(ERROR, "impossible state");
+ elog(ERROR, "unrecognized iterator result: %d", (int) r);
+ res = NULL; /* keep compiler quiet */
+ break;
}
return res;
JsonbValue v;
int idx,
i;
- char *badp;
bool done = false;
/* pick correct index */
{
char *c = TextDatumGetCString(path_elems[level]);
long lindex;
+ char *badp;
errno = 0;
lindex = strtol(c, &badp, 10);
if (errno != 0 || badp == c || *badp != '\0' || lindex > INT_MAX ||
lindex < INT_MIN)
- elog(ERROR, "path element at the position %d is not an integer", level + 1);
- else
- idx = lindex;
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("path element at position %d is not an integer: \"%s\"",
+ level + 1, c)));
+ idx = lindex;
}
else
idx = nelems;
{
addJsonbToParseState(st, newval);
}
-
}
}
}
(1 row)
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{d,NULL,0}', '[1,2,3]');
-ERROR: path element at the position 2 is NULL
+ERROR: path element at position 2 is null
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{n}', '{"1": 2}');
jsonb_set
-------------------------------------------------------------------------
(1 row)
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{d,NULL,0}', '{"1": 2}');
-ERROR: path element at the position 2 is NULL
+ERROR: path element at position 2 is null
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{b,-1}', '"test"');
jsonb_set
--------------------------------------------------------------------------
(1 row)
select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{b,-1e}'; -- invalid array subscript
-ERROR: path element at the position 2 is not an integer
+ERROR: path element at position 2 is not an integer: "-1e"
select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{d,1,0}';
?column?
------------------------------------------------------------------
(1 row)
select jsonb_set('{"a": [1, 2, 3]}', '{a, non_integer}', '"new_value"');
-ERROR: path element at the position 2 is not an integer
+ERROR: path element at position 2 is not an integer: "non_integer"
select jsonb_set('{"a": {"b": [1, 2, 3]}}', '{a, b, non_integer}', '"new_value"');
-ERROR: path element at the position 3 is not an integer
+ERROR: path element at position 3 is not an integer: "non_integer"
select jsonb_set('{"a": {"b": [1, 2, 3]}}', '{a, b, NULL}', '"new_value"');
-ERROR: path element at the position 3 is NULL
+ERROR: path element at position 3 is null