Seems that parser not using precedence ideal order, and that casting
obligation losts performance.
The first problem is self-evident in this example:
SELECT '{"x":1}'::jsonb || (('{"A":{"y":2}}'::jsonb)->'A')
-- it is ok, expected result with (x,y)
SELECT '{"x":1}'::jsonb || '{"A":{"y":2}}'::jsonb)->'A'
-- non-expected result (y).
Higher precedence <https://en.wikipedia.org/wiki/Order_of_operations> most
be for -> operator, that is like an object-oriented *path* operator, always
higher than algebric ones.
Other problem is using this operation as SQL function,
CREATE FUNCTION term_lib.junpack(jsonb,text) RETURNS JSONB AS $f$
SELECT ($1-$2)::JSONB || ($1->>$2)::JSONB;
$f$ LANGUAGE SQL IMMUTABLE;
without casting produce error. Perhaps will be "more friendly" without cast
obligation,
and it is a performance problem, the abusive use of castings losts
performance.