diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-08-20 16:48:37 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-08-20 16:48:37 -0400 |
commit | 04db8747840f581177c6622008d2e42d3528f7fe (patch) | |
tree | 3559ac625ae104995e572d37324741b5cd4d8194 /src/test/regress/sql/json.sql | |
parent | e0d010f64ca2b3b7d41ca961549388cf4fbe8aed (diff) |
Fix core dump in jsonb #> operator, and add regression test cases.
jsonb's #> operator segfaulted (dereferencing a null pointer) if the RHS
was a zero-length array, as reported in bug #11207 from Justin Van Winkle.
json's #> operator returns NULL in such cases, so for the moment let's
make jsonb act likewise.
Also add a bunch of regression test queries memorializing the -> and #>
operators' behavior for this and other corner cases.
There is a good argument for changing some of these behaviors, as they
are not very consistent with each other, and throwing an error isn't
necessarily a desirable behavior for operators that are likely to be
used in indexes. However, everybody can agree that a core dump is the
Wrong Thing, and we need test cases even if we decide to change their
expected output later.
Diffstat (limited to 'src/test/regress/sql/json.sql')
-rw-r--r-- | src/test/regress/sql/json.sql | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/test/regress/sql/json.sql b/src/test/regress/sql/json.sql index ae65ef6921e..964d5baa2a4 100644 --- a/src/test/regress/sql/json.sql +++ b/src/test/regress/sql/json.sql @@ -238,6 +238,17 @@ select (test_json->>3) is null as expect_true from test_json where json_type = 'array'; +-- corner cases + +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> null::text; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> null::int; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> 1; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> 'z'; +select '[{"b": "c"}, {"b": "cc"}]'::json -> 1; +select '[{"b": "c"}, {"b": "cc"}]'::json -> 3; +select '[{"b": "c"}, {"b": "cc"}]'::json -> 'z'; +select '"foo"'::json -> 1; +select '"foo"'::json -> 'z'; -- array length @@ -281,20 +292,40 @@ select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>array['f4','f6']; select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>array['f2']; select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>array['f2','0']; select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>array['f2','1']; + select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>>array['f4','f6']; select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>>array['f2']; select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>>array['f2','0']; select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>>array['f2','1']; --- same using array literals -select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>'{f4,f6}'; -select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>'{f2}'; -select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>'{f2,0}'; -select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>'{f2,1}'; -select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>>'{f4,f6}'; -select '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}'::json#>>'{f2}'; -select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>>'{f2,0}'; -select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>>'{f2,1}'; +-- corner cases for same +select '{"a": {"b":{"c": "foo"}}}'::json #> array[]::text[]; +select '{"a": {"b":{"c": "foo"}}}'::json #> array['a']; +select '{"a": {"b":{"c": "foo"}}}'::json #> array['a','b']; +select '{"a": {"b":{"c": "foo"}}}'::json #> array['a','b','c']; +select '{"a": {"b":{"c": "foo"}}}'::json #> array['a','b','c','d']; +select '{"a": {"b":{"c": "foo"}}}'::json #> array['a','z','c']; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json #> array['a','1','b']; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json #> array['a','z','b']; +select '[{"b": "c"}, {"b": "cc"}]'::json #> array['1','b']; +select '[{"b": "c"}, {"b": "cc"}]'::json #> array['z','b']; +select '"foo"'::json #> array['z']; +select '42'::json #> array['f2']; +select '42'::json #> array['0']; + +select '{"a": {"b":{"c": "foo"}}}'::json #>> array[]::text[]; +select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a']; +select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a','b']; +select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a','b','c']; +select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a','b','c','d']; +select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a','z','c']; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json #>> array['a','1','b']; +select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json #>> array['a','z','b']; +select '[{"b": "c"}, {"b": "cc"}]'::json #>> array['1','b']; +select '[{"b": "c"}, {"b": "cc"}]'::json #>> array['z','b']; +select '"foo"'::json #>> array['z']; +select '42'::json #>> array['f2']; +select '42'::json #>> array['0']; -- array_elements |