(1 row)
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> '';
+ ?column?
+----------
+
+(1 row)
+
select '[{"b": "c"}, {"b": "cc"}]'::json -> 1;
?column?
-------------
ERROR: cannot extract element from a scalar
select '"foo"'::json -> 'z';
ERROR: cannot extract element from a scalar
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> null::text;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> null::int;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> 1;
+ERROR: cannot extract array element from a non-array
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> 'z';
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> '';
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::json ->> 1;
+ ?column?
+-------------
+ {"b": "cc"}
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::json ->> 3;
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::json ->> 'z';
+ERROR: cannot extract field from a non-object
+select '"foo"'::json ->> 1;
+ERROR: cannot extract element from a scalar
+select '"foo"'::json ->> 'z';
+ERROR: cannot extract element from a scalar
-- array length
SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
json_array_length
(1 row)
-- corner cases for same
-select '{"a": {"b":{"c": "foo"}}}'::json #> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::json #> '{}';
?column?
----------
{"b":{"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::json #> array['a', null];
+ERROR: cannot call json_extract_path with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::json #> array['a', ''];
+ERROR: cannot call json_extract_path with empty path elements
select '{"a": {"b":{"c": "foo"}}}'::json #> array['a','b'];
?column?
--------------
(1 row)
-select '{"a": {"b":{"c": "foo"}}}'::json #>> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::json #>> '{}';
?column?
----------
{"b":{"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a', null];
+ERROR: cannot call json_extract_path_text with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a', ''];
+ERROR: cannot call json_extract_path_text with empty path elements
select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a','b'];
?column?
--------------
(1 row)
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> '';
+ ?column?
+----------
+
+(1 row)
+
select '[{"b": "c"}, {"b": "cc"}]'::json -> 1;
?column?
-------------
ERROR: cannot extract element from a scalar
select '"foo"'::json -> 'z';
ERROR: cannot extract element from a scalar
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> null::text;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> null::int;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> 1;
+ERROR: cannot extract array element from a non-array
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> 'z';
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> '';
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::json ->> 1;
+ ?column?
+-------------
+ {"b": "cc"}
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::json ->> 3;
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::json ->> 'z';
+ERROR: cannot extract field from a non-object
+select '"foo"'::json ->> 1;
+ERROR: cannot extract element from a scalar
+select '"foo"'::json ->> 'z';
+ERROR: cannot extract element from a scalar
-- array length
SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
json_array_length
(1 row)
-- corner cases for same
-select '{"a": {"b":{"c": "foo"}}}'::json #> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::json #> '{}';
?column?
----------
{"b":{"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::json #> array['a', null];
+ERROR: cannot call json_extract_path with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::json #> array['a', ''];
+ERROR: cannot call json_extract_path with empty path elements
select '{"a": {"b":{"c": "foo"}}}'::json #> array['a','b'];
?column?
--------------
(1 row)
-select '{"a": {"b":{"c": "foo"}}}'::json #>> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::json #>> '{}';
?column?
----------
{"b":{"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a', null];
+ERROR: cannot call json_extract_path_text with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a', ''];
+ERROR: cannot call json_extract_path_text with empty path elements
select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a','b'];
?column?
--------------
(1 row)
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> '';
+ ?column?
+----------
+
+(1 row)
+
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 1;
?column?
-------------
ERROR: cannot call jsonb_array_element (jsonb -> int) on a scalar
select '"foo"'::jsonb -> 'z';
ERROR: cannot call jsonb_object_field (jsonb -> text) on a scalar
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::text;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::int;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 1;
+ERROR: cannot call jsonb_array_element_text on an object
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 'z';
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> '';
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 1;
+ ?column?
+-------------
+ {"b": "cc"}
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 3;
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 'z';
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on an array
+select '"foo"'::jsonb ->> 1;
+ERROR: cannot call jsonb_array_element_text on a scalar
+select '"foo"'::jsonb ->> 'z';
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on a scalar
-- equality and inequality
SELECT '{"x":"y"}'::jsonb = '{"x":"y"}'::jsonb;
?column?
(1 row)
-- corner cases for same
-select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> '{}';
?column?
----------
{"b": {"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a', null];
+ERROR: cannot call jsonb_extract_path with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a', ''];
+ ?column?
+----------
+
+(1 row)
+
select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a','b'];
?column?
--------------
ERROR: cannot extract path from a scalar
select '42'::jsonb #> array['0'];
ERROR: cannot extract path from a scalar
-select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> '{}';
?column?
----------
{"b": {"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a', null];
+ERROR: cannot call jsonb_extract_path_text with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a', ''];
+ ?column?
+----------
+
+(1 row)
+
select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a','b'];
?column?
--------------
(1 row)
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> '';
+ ?column?
+----------
+
+(1 row)
+
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 1;
?column?
-------------
ERROR: cannot call jsonb_array_element (jsonb -> int) on a scalar
select '"foo"'::jsonb -> 'z';
ERROR: cannot call jsonb_object_field (jsonb -> text) on a scalar
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::text;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::int;
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 1;
+ERROR: cannot call jsonb_array_element_text on an object
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 'z';
+ ?column?
+----------
+
+(1 row)
+
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> '';
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 1;
+ ?column?
+-------------
+ {"b": "cc"}
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 3;
+ ?column?
+----------
+
+(1 row)
+
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 'z';
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on an array
+select '"foo"'::jsonb ->> 1;
+ERROR: cannot call jsonb_array_element_text on a scalar
+select '"foo"'::jsonb ->> 'z';
+ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on a scalar
-- equality and inequality
SELECT '{"x":"y"}'::jsonb = '{"x":"y"}'::jsonb;
?column?
(1 row)
-- corner cases for same
-select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> '{}';
?column?
----------
{"b": {"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a', null];
+ERROR: cannot call jsonb_extract_path with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a', ''];
+ ?column?
+----------
+
+(1 row)
+
select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a','b'];
?column?
--------------
ERROR: cannot extract path from a scalar
select '42'::jsonb #> array['0'];
ERROR: cannot extract path from a scalar
-select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> '{}';
?column?
----------
{"b": {"c": "foo"}}
(1 row)
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a', null];
+ERROR: cannot call jsonb_extract_path_text with null path elements
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a', ''];
+ ?column?
+----------
+
+(1 row)
+
select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a','b'];
?column?
--------------
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 '{"a": [{"b": "c"}, {"b": "cc"}]}'::json -> '';
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';
+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 '{"a": [{"b": "c"}, {"b": "cc"}]}'::json ->> '';
+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
SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
select '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::json#>>array['f2','1'];
-- corner cases for same
-select '{"a": {"b":{"c": "foo"}}}'::json #> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::json #> '{}';
select '{"a": {"b":{"c": "foo"}}}'::json #> array['a'];
+select '{"a": {"b":{"c": "foo"}}}'::json #> array['a', null];
+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 '42'::json #> array['f2'];
select '42'::json #> array['0'];
-select '{"a": {"b":{"c": "foo"}}}'::json #>> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::json #>> '{}';
select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a'];
+select '{"a": {"b":{"c": "foo"}}}'::json #>> array['a', null];
+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"}, {"b": "cc"}]}'::jsonb -> null::int;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> 1;
select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> 'z';
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb -> '';
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 1;
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 3;
select '[{"b": "c"}, {"b": "cc"}]'::jsonb -> 'z';
select '"foo"'::jsonb -> 1;
select '"foo"'::jsonb -> 'z';
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::text;
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> null::int;
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 1;
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> 'z';
+select '{"a": [{"b": "c"}, {"b": "cc"}]}'::jsonb ->> '';
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 1;
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 3;
+select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 'z';
+select '"foo"'::jsonb ->> 1;
+select '"foo"'::jsonb ->> 'z';
+
-- equality and inequality
SELECT '{"x":"y"}'::jsonb = '{"x":"y"}'::jsonb;
SELECT '{"x":"y"}'::jsonb = '{"x":"z"}'::jsonb;
SELECT '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::jsonb#>>array['f2','1'];
-- corner cases for same
-select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> '{}';
select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a'];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a', null];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a', ''];
select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a','b'];
select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a','b','c'];
select '{"a": {"b":{"c": "foo"}}}'::jsonb #> array['a','b','c','d'];
select '42'::jsonb #> array['f2'];
select '42'::jsonb #> array['0'];
-select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array[]::text[];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> '{}';
select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a'];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a', null];
+select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a', ''];
select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a','b'];
select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a','b','c'];
select '{"a": {"b":{"c": "foo"}}}'::jsonb #>> array['a','b','c','d'];