Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions regress/expected/jsonb_operators.out
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,30 @@ SELECT '{"a": 9, "b": 11, "c": {"ca": [[], {}, null]}, "d": true, "1": false}'::

(1 row)

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"1"'::agtype;
?column?
----------

(1 row)

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> 1::text;
?column?
----------

(1 row)

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"a"';
?column?
----------

(1 row)

SELECT 'null'::agtype -> '"1"';
?column?
----------

(1 row)

-- LHS is an array
SELECT '["a","b","c",[1,2],null]'::agtype -> '0'::agtype;
?column?
Expand Down Expand Up @@ -1241,6 +1265,30 @@ SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype ->> null::int;

(1 row)

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"1"'::agtype;
?column?
----------

(1 row)

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> 1::text;
?column?
----------

(1 row)

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"a"';
?column?
----------

(1 row)

SELECT 'null'::agtype ->> '"1"';
?column?
----------

(1 row)

-- LHS is an array
SELECT '["a","b","c",[1,2],null]'::agtype ->> 0;
?column?
Expand Down
12 changes: 12 additions & 0 deletions regress/sql/jsonb_operators.sql
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype -> null::int;
SELECT '{"a": [-1, -2, -3]}'::agtype -> '"a"'::text;
SELECT '{"a": 9, "b": 11, "c": {"ca": [[], {}, null]}, "d": true, "1": false}'::agtype -> '1'::text::agtype;

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"1"'::agtype;
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> 1::text;
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype -> '"a"';

SELECT 'null'::agtype -> '"1"';

-- LHS is an array
SELECT '["a","b","c",[1,2],null]'::agtype -> '0'::agtype;
SELECT '["a","b","c",[1,2],null]'::agtype -> 1;
Expand Down Expand Up @@ -288,6 +294,12 @@ SELECT '{"1": -1.99, "a": 1, "b": 2, "c": {"d": [{}, [[[], [9]]]]}, "1": true}':
SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype ->> null::text;
SELECT '{"a": [{"b": "c"}, {"b": "cc"}]}'::agtype ->> null::int;

SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"1"'::agtype;
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> 1::text;
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"automatically":{"1":[2,3]}}'::agtype -> '"n"'::agtype ->> '"a"';

SELECT 'null'::agtype ->> '"1"';

-- LHS is an array
SELECT '["a","b","c",[1,2],null]'::agtype ->> 0;
SELECT '["a","b","c",[1,2],null]'::agtype ->> '1'::agtype;
Expand Down
11 changes: 8 additions & 3 deletions src/backend/utils/adt/agtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -3644,9 +3644,14 @@ Datum agtype_object_field_impl(FunctionCallInfo fcinfo, agtype *agtype_in,

if (AGT_ROOT_IS_SCALAR(agtype_in))
{
process_agtype =
agtype_value_to_agtype(extract_entity_properties(agtype_in,
false));
agtype_value *process_agtv = extract_entity_properties(agtype_in,
false);
if (!process_agtv)
{
PG_RETURN_NULL();
}

process_agtype = agtype_value_to_agtype(process_agtv);
}
else
{
Expand Down