if (jbv->type == jbvBinary &&
JsonContainerIsObject(jbv->val.binary.data))
+ {
jso->val.jsonb_cont = jbv->val.binary.data;
+ }
else
- jso->val.jsonb_cont = NULL;
+ {
+ bool is_scalar;
+
+ is_scalar = IsAJsonbScalar(jbv) ||
+ (jbv->type == jbvBinary &&
+ JsonContainerIsScalar(jbv->val.binary.data));
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ is_scalar
+ ? errmsg("cannot call %s on a scalar",
+ "populate_composite")
+ : errmsg("cannot call %s on an array",
+ "populate_composite")));
+ }
}
}
(1 row)
SELECT rec FROM jsonb_populate_record(NULL::jsbrec, '{"rec": 123}') q;
- rec
-------
- (,,)
-(1 row)
-
+ERROR: cannot call populate_composite on a scalar
SELECT rec FROM jsonb_populate_record(NULL::jsbrec, '{"rec": [1, 2]}') q;
- rec
-------
- (,,)
-(1 row)
-
+ERROR: cannot call populate_composite on an array
SELECT rec FROM jsonb_populate_record(NULL::jsbrec, '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}') q;
rec
-----------------------------------
ERROR: expected json array
HINT: see the value of key "reca"
SELECT reca FROM jsonb_populate_record(NULL::jsbrec, '{"reca": [1, 2]}') q;
- reca
------------------
- {"(,,)","(,,)"}
-(1 row)
-
+ERROR: cannot call populate_composite on a scalar
SELECT reca FROM jsonb_populate_record(NULL::jsbrec, '{"reca": [{"a": "abc", "b": 456}, null, {"c": "01.02.2003", "x": 43.2}]}') q;
reca
--------------------------------------------------------