+ /* check that supplied jsonb isn't non object, i.e. scalar or array */
+ if (!JB_ROOT_IS_OBJECT(input_jsonb_a) || !JB_ROOT_IS_OBJECT(input_jsonb_b))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("cannot call on a non-object")));
+
+ /*
+ * check if either supplied jsonb is empty and return the other if so
+ * this idea was copied from https://github.com/erthalion/jsonbx/blob/master/jsonbx.c
+ */
+ if (JB_ROOT_COUNT(input_jsonb_b) == 0)
+ PG_RETURN_JSONB(input_jsonb_a);
+