#include "utils/typcache.h"
/* Operations available for setPath */
-#define JB_PATH_NOOP 0x0000
#define JB_PATH_CREATE 0x0001
#define JB_PATH_DELETE 0x0002
-#define JB_PATH_INSERT_BEFORE 0x0004
-#define JB_PATH_INSERT_AFTER 0x0008
+#define JB_PATH_REPLACE 0x0004
+#define JB_PATH_INSERT_BEFORE 0x0008
+#define JB_PATH_INSERT_AFTER 0x0010
#define JB_PATH_CREATE_OR_INSERT \
(JB_PATH_INSERT_BEFORE | JB_PATH_INSERT_AFTER | JB_PATH_CREATE)
it = JsonbIteratorInit(&in->root);
res = setPath(&it, path_elems, path_nulls, path_len, &st,
- 0, newval, create ? JB_PATH_CREATE : JB_PATH_NOOP);
+ 0, newval, create ? JB_PATH_CREATE : JB_PATH_REPLACE);
Assert(res != NULL);
if (op_type & (JB_PATH_INSERT_AFTER | JB_PATH_INSERT_BEFORE))
(void) pushJsonbValue(st, r, &v);
- if (op_type & JB_PATH_INSERT_AFTER)
+ if (op_type & (JB_PATH_INSERT_AFTER | JB_PATH_REPLACE))
addJsonbToParseState(st, newval);
done = true;
}
}
- if (op_type & JB_PATH_CREATE_OR_INSERT && !done &&
+ if ((op_type & JB_PATH_CREATE_OR_INSERT) && !done &&
level == path_len - 1 && i == nelems - 1)
{
addJsonbToParseState(st, newval);
[]
(1 row)
+select jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0}','[2,3,4]', false);
+ jsonb_set
+-------------------------
+ [[2, 3, 4], 2, null, 3]
+(1 row)
+
-- jsonb_set adding instead of replacing
-- prepend to array
select jsonb_set('{"a":1,"b":[0,1,2],"c":{"d":4}}','{b,-33}','{"foo":123}');
select jsonb_set('"a"','{a}','"b"'); --error
select jsonb_set('{}','{a}','"b"', false);
select jsonb_set('[]','{1}','"b"', false);
+select jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0}','[2,3,4]', false);
-- jsonb_set adding instead of replacing