Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Correct handling of array extractors

  • Loading branch information...
commit 7f27e545323e306e1dc0f4d11f1a4be7e46ac092 1 parent 42f8af4
@theirix authored
View
6 expected/json_accessors_c.out
@@ -81,5 +81,11 @@ select json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "b
-- baz2
select (json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar')))[2];
baz2
+-- {"{\"foo\":42}","{\"bar\":[]}"}
+select json_array_to_object_array('[{"foo":42}, {"bar":[]}]');
+{"{\"foo\":42}","{\"bar\":[]}"}
+-- {"[\"foo\",\"bar\"]",[]}
+select json_array_to_multi_array('[["foo", "bar"], []]');
+{"[\"foo\",\"bar\"]",[]}
\t off
\pset format aligned
View
11 json_accessors.c
@@ -287,16 +287,11 @@ Datum json_array_to_array_generic_impl(cJSON *jsonArray, int json_type, Oid elem
for (elem = jsonArray->child; elem; elem = elem->next)
{
- /*todo [alexey]: check this change*/
- if (elem->child)
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("no childs allowed")));
if (!(json_type == CJSON_TYPE_ANY || match_json_types(json_type, elem->type)))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("expected value of type %s, actual %s at %d position",
- json_type_str(json_type), json_type_str(elem->type), ind)));
+ json_type_str(json_type), json_type_str(elem->type), count)));
++count;
}
@@ -540,7 +535,7 @@ Datum json_get_timestamp(PG_FUNCTION_ARGS)
*/
Datum json_array_to_object_array(PG_FUNCTION_ARGS)
{
- return json_array_to_array_generic_args(fcinfo, cJSON_String, TEXTOID, extract_json_to_string);
+ return json_array_to_array_generic_args(fcinfo, CJSON_TYPE_ANY, TEXTOID, extract_json_to_string);
}
/**
@@ -550,7 +545,7 @@ Datum json_array_to_object_array(PG_FUNCTION_ARGS)
*/
Datum json_array_to_multi_array(PG_FUNCTION_ARGS)
{
- return json_array_to_array_generic_args(fcinfo, cJSON_String, TEXTOID, extract_json_to_string);
+ return json_array_to_array_generic_args(fcinfo, CJSON_TYPE_ANY, TEXTOID, extract_json_to_string);
}
Datum json_array_to_text_array(PG_FUNCTION_ARGS)
View
5 sql/json_accessors_c.sql
@@ -63,5 +63,10 @@ select json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "b
-- baz2
select (json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar')))[2];
+-- {"{\"foo\":42}","{\"bar\":[]}"}
+select json_array_to_object_array('[{"foo":42}, {"bar":[]}]');
+-- {"[\"foo\",\"bar\"]",[]}
+select json_array_to_multi_array('[["foo", "bar"], []]');
+
\t off
\pset format aligned
Please sign in to comment.
Something went wrong with that request. Please try again.