errmsg("null value not allowed for object key")));
v = TextDatumGetCString(in_datums[i * 2]);
- if (v[0] == '\0')
- ereport(ERROR,
- (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("empty value not allowed for object key")));
if (i > 0)
appendStringInfoString(&result, ", ");
escape_json(&result, v);
errmsg("null value not allowed for object key")));
v = TextDatumGetCString(key_datums[i]);
- if (v[0] == '\0')
- ereport(ERROR,
- (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("empty value not allowed for object key")));
if (i > 0)
appendStringInfoString(&result, ", ");
escape_json(&result, v);
-- null key error
select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}');
ERROR: null value not allowed for object key
--- empty key error
+-- empty key is allowed
select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}');
-ERROR: empty value not allowed for object key
+ json_object
+-----------------------------------------------------
+ {"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"}
+(1 row)
+
-- json_to_record and json_to_recordset
select * from json_to_record('{"a":1,"b":"foo","c":"bar"}')
as x(a int, b text, d text);
-- null key error
select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}');
ERROR: null value not allowed for object key
--- empty key error
+-- empty key is allowed
select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}');
-ERROR: empty value not allowed for object key
+ json_object
+-----------------------------------------------------
+ {"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"}
+(1 row)
+
-- json_to_record and json_to_recordset
select * from json_to_record('{"a":1,"b":"foo","c":"bar"}')
as x(a int, b text, d text);
select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}');
--- empty key error
+-- empty key is allowed
select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}');