mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix the fastpath rule for jsonb_concat with an empty operand.
To prevent perverse results, we now only return the other operand if it's not scalar, and if both operands are of the same kind (array or object). Original bug complaint and patch from Oskari Saarenmaa, extended by me to cover the cases of different kinds of jsonb. Backpatch to 9.5 where jsonb_concat was introduced.
This commit is contained in:
@ -2912,6 +2912,42 @@ select '"c"' || '["a", "b"]'::jsonb;
|
||||
["c", "a", "b"]
|
||||
(1 row)
|
||||
|
||||
select '[]'::jsonb || '["a"]'::jsonb;
|
||||
?column?
|
||||
----------
|
||||
["a"]
|
||||
(1 row)
|
||||
|
||||
select '[]'::jsonb || '"a"'::jsonb;
|
||||
?column?
|
||||
----------
|
||||
["a"]
|
||||
(1 row)
|
||||
|
||||
select '"b"'::jsonb || '"a"'::jsonb;
|
||||
?column?
|
||||
------------
|
||||
["b", "a"]
|
||||
(1 row)
|
||||
|
||||
select '{}'::jsonb || '{"a":"b"}'::jsonb;
|
||||
?column?
|
||||
------------
|
||||
{"a": "b"}
|
||||
(1 row)
|
||||
|
||||
select '[]'::jsonb || '{"a":"b"}'::jsonb;
|
||||
?column?
|
||||
--------------
|
||||
[{"a": "b"}]
|
||||
(1 row)
|
||||
|
||||
select '{"a":"b"}'::jsonb || '[]'::jsonb;
|
||||
?column?
|
||||
--------------
|
||||
[{"a": "b"}]
|
||||
(1 row)
|
||||
|
||||
select '"a"'::jsonb || '{"a":1}';
|
||||
ERROR: invalid concatenation of jsonb objects
|
||||
select '{"a":1}' || '"a"'::jsonb;
|
||||
|
@ -2912,6 +2912,42 @@ select '"c"' || '["a", "b"]'::jsonb;
|
||||
["c", "a", "b"]
|
||||
(1 row)
|
||||
|
||||
select '[]'::jsonb || '["a"]'::jsonb;
|
||||
?column?
|
||||
----------
|
||||
["a"]
|
||||
(1 row)
|
||||
|
||||
select '[]'::jsonb || '"a"'::jsonb;
|
||||
?column?
|
||||
----------
|
||||
["a"]
|
||||
(1 row)
|
||||
|
||||
select '"b"'::jsonb || '"a"'::jsonb;
|
||||
?column?
|
||||
------------
|
||||
["b", "a"]
|
||||
(1 row)
|
||||
|
||||
select '{}'::jsonb || '{"a":"b"}'::jsonb;
|
||||
?column?
|
||||
------------
|
||||
{"a": "b"}
|
||||
(1 row)
|
||||
|
||||
select '[]'::jsonb || '{"a":"b"}'::jsonb;
|
||||
?column?
|
||||
--------------
|
||||
[{"a": "b"}]
|
||||
(1 row)
|
||||
|
||||
select '{"a":"b"}'::jsonb || '[]'::jsonb;
|
||||
?column?
|
||||
--------------
|
||||
[{"a": "b"}]
|
||||
(1 row)
|
||||
|
||||
select '"a"'::jsonb || '{"a":1}';
|
||||
ERROR: invalid concatenation of jsonb objects
|
||||
select '{"a":1}' || '"a"'::jsonb;
|
||||
|
@ -718,6 +718,13 @@ select '["c"]' || '["a", "b"]'::jsonb;
|
||||
select '["a", "b"]'::jsonb || '"c"';
|
||||
select '"c"' || '["a", "b"]'::jsonb;
|
||||
|
||||
select '[]'::jsonb || '["a"]'::jsonb;
|
||||
select '[]'::jsonb || '"a"'::jsonb;
|
||||
select '"b"'::jsonb || '"a"'::jsonb;
|
||||
select '{}'::jsonb || '{"a":"b"}'::jsonb;
|
||||
select '[]'::jsonb || '{"a":"b"}'::jsonb;
|
||||
select '{"a":"b"}'::jsonb || '[]'::jsonb;
|
||||
|
||||
select '"a"'::jsonb || '{"a":1}';
|
||||
select '{"a":1}' || '"a"'::jsonb;
|
||||
|
||||
|
Reference in New Issue
Block a user