From: Andrew Dunstan Date: Tue, 18 Mar 2014 15:40:38 +0000 (-0400) Subject: Improve regression test code coverage for jsonb and json. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=485b045a53a23c2f74d0b187c4c5622a1111a27e;p=users%2Fandresfreund%2Fpostgres.git Improve regression test code coverage for jsonb and json. --- diff --git a/src/test/regress/expected/json.out b/src/test/regress/expected/json.out index 04b969ae10..7437ea9f67 100644 --- a/src/test/regress/expected/json.out +++ b/src/test/regress/expected/json.out @@ -464,8 +464,8 @@ CREATE TEMP TABLE test_json ( ); INSERT INTO test_json VALUES ('scalar','"a scalar"'), -('array','["zero", "one","two",null,"four","five"]'), -('object','{"field1":"val1","field2":"val2","field3":null}'); +('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), +('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); SELECT test_json -> 'x' FROM test_json WHERE json_type = 'scalar'; @@ -522,6 +522,36 @@ WHERE json_type = 'array'; two (1 row) +SELECT test_json ->> 6 FROM test_json WHERE json_type = 'array'; + ?column? +---------- + [1,2,3] +(1 row) + +SELECT test_json ->> 7 FROM test_json WHERE json_type = 'array'; + ?column? +---------- + {"f1":9} +(1 row) + +SELECT test_json ->> 'field4' FROM test_json WHERE json_type = 'object'; + ?column? +---------- + 4 +(1 row) + +SELECT test_json ->> 'field5' FROM test_json WHERE json_type = 'object'; + ?column? +---------- + [1,2,3] +(1 row) + +SELECT test_json ->> 'field6' FROM test_json WHERE json_type = 'object'; + ?column? +---------- + {"f1":9} +(1 row) + SELECT json_object_keys(test_json) FROM test_json WHERE json_type = 'scalar'; @@ -538,7 +568,20 @@ WHERE json_type = 'object'; field1 field2 field3 -(3 rows) + field4 + field5 + field6 +(6 rows) + +-- test extending object_keys resultset - initial resultset size is 256 +select count(*) from + (select json_object_keys(json_object(array_agg(g))) + from (select unnest(array['f'||n,n::text])as g + from generate_series(1,300) as n) x ) y; + count +------- + 300 +(1 row) -- nulls select (test_json->'field3') is null as expect_false diff --git a/src/test/regress/expected/json_1.out b/src/test/regress/expected/json_1.out index 07b25ca96c..4caf92fcf3 100644 --- a/src/test/regress/expected/json_1.out +++ b/src/test/regress/expected/json_1.out @@ -464,8 +464,8 @@ CREATE TEMP TABLE test_json ( ); INSERT INTO test_json VALUES ('scalar','"a scalar"'), -('array','["zero", "one","two",null,"four","five"]'), -('object','{"field1":"val1","field2":"val2","field3":null}'); +('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), +('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); SELECT test_json -> 'x' FROM test_json WHERE json_type = 'scalar'; @@ -522,6 +522,36 @@ WHERE json_type = 'array'; two (1 row) +SELECT test_json ->> 6 FROM test_json WHERE json_type = 'array'; + ?column? +---------- + [1,2,3] +(1 row) + +SELECT test_json ->> 7 FROM test_json WHERE json_type = 'array'; + ?column? +---------- + {"f1":9} +(1 row) + +SELECT test_json ->> 'field4' FROM test_json WHERE json_type = 'object'; + ?column? +---------- + 4 +(1 row) + +SELECT test_json ->> 'field5' FROM test_json WHERE json_type = 'object'; + ?column? +---------- + [1,2,3] +(1 row) + +SELECT test_json ->> 'field6' FROM test_json WHERE json_type = 'object'; + ?column? +---------- + {"f1":9} +(1 row) + SELECT json_object_keys(test_json) FROM test_json WHERE json_type = 'scalar'; @@ -538,7 +568,20 @@ WHERE json_type = 'object'; field1 field2 field3 -(3 rows) + field4 + field5 + field6 +(6 rows) + +-- test extending object_keys resultset - initial resultset size is 256 +select count(*) from + (select json_object_keys(json_object(array_agg(g))) + from (select unnest(array['f'||n,n::text])as g + from generate_series(1,300) as n) x ) y; + count +------- + 300 +(1 row) -- nulls select (test_json->'field3') is null as expect_false diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/jsonb.out index 686f8efddc..b425307755 100644 --- a/src/test/regress/expected/jsonb.out +++ b/src/test/regress/expected/jsonb.out @@ -308,8 +308,8 @@ CREATE TEMP TABLE test_jsonb ( ); INSERT INTO test_jsonb VALUES ('scalar','"a scalar"'), -('array','["zero", "one","two",null,"four","five"]'), -('object','{"field1":"val1","field2":"val2","field3":null}'); +('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), +('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar'; ERROR: cannot call jsonb_object_field (jsonb -> text operator) on a scalar SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array'; @@ -352,6 +352,36 @@ SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object'; ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object +SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array'; + ?column? +----------- + [1, 2, 3] +(1 row) + +SELECT test_json ->> 7 FROM test_jsonb WHERE json_type = 'array'; + ?column? +----------- + {"f1": 9} +(1 row) + +SELECT test_json ->> 'field4' FROM test_jsonb WHERE json_type = 'object'; + ?column? +---------- + 4 +(1 row) + +SELECT test_json ->> 'field5' FROM test_jsonb WHERE json_type = 'object'; + ?column? +----------- + [1, 2, 3] +(1 row) + +SELECT test_json ->> 'field6' FROM test_jsonb WHERE json_type = 'object'; + ?column? +----------- + {"f1": 9} +(1 row) + SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'scalar'; ERROR: cannot call jsonb_array_element_text on a scalar SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'array'; @@ -372,7 +402,10 @@ SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'object'; field1 field2 field3 -(3 rows) + field4 + field5 + field6 +(6 rows) -- nulls SELECT (test_json->'field3') IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'object'; diff --git a/src/test/regress/expected/jsonb_1.out b/src/test/regress/expected/jsonb_1.out index 7c15b4c847..65b68a5a80 100644 --- a/src/test/regress/expected/jsonb_1.out +++ b/src/test/regress/expected/jsonb_1.out @@ -308,8 +308,8 @@ CREATE TEMP TABLE test_jsonb ( ); INSERT INTO test_jsonb VALUES ('scalar','"a scalar"'), -('array','["zero", "one","two",null,"four","five"]'), -('object','{"field1":"val1","field2":"val2","field3":null}'); +('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), +('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar'; ERROR: cannot call jsonb_object_field (jsonb -> text operator) on a scalar SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array'; @@ -352,6 +352,36 @@ SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object'; ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object +SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array'; + ?column? +----------- + [1, 2, 3] +(1 row) + +SELECT test_json ->> 7 FROM test_jsonb WHERE json_type = 'array'; + ?column? +----------- + {"f1": 9} +(1 row) + +SELECT test_json ->> 'field4' FROM test_jsonb WHERE json_type = 'object'; + ?column? +---------- + 4 +(1 row) + +SELECT test_json ->> 'field5' FROM test_jsonb WHERE json_type = 'object'; + ?column? +----------- + [1, 2, 3] +(1 row) + +SELECT test_json ->> 'field6' FROM test_jsonb WHERE json_type = 'object'; + ?column? +----------- + {"f1": 9} +(1 row) + SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'scalar'; ERROR: cannot call jsonb_array_element_text on a scalar SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'array'; @@ -372,7 +402,10 @@ SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'object'; field1 field2 field3 -(3 rows) + field4 + field5 + field6 +(6 rows) -- nulls SELECT (test_json->'field3') IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'object'; diff --git a/src/test/regress/sql/json.sql b/src/test/regress/sql/json.sql index 2d3f0bcc61..96000c7df7 100644 --- a/src/test/regress/sql/json.sql +++ b/src/test/regress/sql/json.sql @@ -136,8 +136,8 @@ CREATE TEMP TABLE test_json ( INSERT INTO test_json VALUES ('scalar','"a scalar"'), -('array','["zero", "one","two",null,"four","five"]'), -('object','{"field1":"val1","field2":"val2","field3":null}'); +('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), +('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); SELECT test_json -> 'x' FROM test_json @@ -175,6 +175,13 @@ SELECT test_json->>2 FROM test_json WHERE json_type = 'array'; +SELECT test_json ->> 6 FROM test_json WHERE json_type = 'array'; +SELECT test_json ->> 7 FROM test_json WHERE json_type = 'array'; + +SELECT test_json ->> 'field4' FROM test_json WHERE json_type = 'object'; +SELECT test_json ->> 'field5' FROM test_json WHERE json_type = 'object'; +SELECT test_json ->> 'field6' FROM test_json WHERE json_type = 'object'; + SELECT json_object_keys(test_json) FROM test_json WHERE json_type = 'scalar'; @@ -187,6 +194,13 @@ SELECT json_object_keys(test_json) FROM test_json WHERE json_type = 'object'; +-- test extending object_keys resultset - initial resultset size is 256 + +select count(*) from + (select json_object_keys(json_object(array_agg(g))) + from (select unnest(array['f'||n,n::text])as g + from generate_series(1,300) as n) x ) y; + -- nulls select (test_json->'field3') is null as expect_false diff --git a/src/test/regress/sql/jsonb.sql b/src/test/regress/sql/jsonb.sql index 21f4da9505..847aa7a78e 100644 --- a/src/test/regress/sql/jsonb.sql +++ b/src/test/regress/sql/jsonb.sql @@ -70,8 +70,8 @@ CREATE TEMP TABLE test_jsonb ( INSERT INTO test_jsonb VALUES ('scalar','"a scalar"'), -('array','["zero", "one","two",null,"four","five"]'), -('object','{"field1":"val1","field2":"val2","field3":null}'); +('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), +('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array'; @@ -87,6 +87,13 @@ SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object'; +SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array'; +SELECT test_json ->> 7 FROM test_jsonb WHERE json_type = 'array'; + +SELECT test_json ->> 'field4' FROM test_jsonb WHERE json_type = 'object'; +SELECT test_json ->> 'field5' FROM test_jsonb WHERE json_type = 'object'; +SELECT test_json ->> 'field6' FROM test_jsonb WHERE json_type = 'object'; + SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'object';