diff options
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 |