Commit 97c4d9b7 authored by Noah Misch's avatar Noah Misch

Don't emit non-canonical empty arrays in array_remove().

Dean Rasheed
parent 01497e73
...@@ -5398,6 +5398,14 @@ array_replace_internal(ArrayType *array, ...@@ -5398,6 +5398,14 @@ array_replace_internal(ArrayType *array,
return array; return array;
} }
/* If all elements were removed return an empty array */
if (nresult == 0)
{
pfree(values);
pfree(nulls);
return construct_empty_array(element_type);
}
/* Allocate and initialize the result array */ /* Allocate and initialize the result array */
if (hasnulls) if (hasnulls)
{ {
......
...@@ -1577,6 +1577,12 @@ select array_remove(array['A','CC','D','C','RR'], 'RR'); ...@@ -1577,6 +1577,12 @@ select array_remove(array['A','CC','D','C','RR'], 'RR');
select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed
ERROR: removing elements from multidimensional arrays is not supported ERROR: removing elements from multidimensional arrays is not supported
select array_remove(array['X','X','X'], 'X') = '{}';
?column?
----------
t
(1 row)
select array_replace(array[1,2,5,4],5,3); select array_replace(array[1,2,5,4],5,3);
array_replace array_replace
--------------- ---------------
......
...@@ -438,6 +438,7 @@ select array_remove(array[1,2,2,3], 5); ...@@ -438,6 +438,7 @@ select array_remove(array[1,2,2,3], 5);
select array_remove(array[1,NULL,NULL,3], NULL); select array_remove(array[1,NULL,NULL,3], NULL);
select array_remove(array['A','CC','D','C','RR'], 'RR'); select array_remove(array['A','CC','D','C','RR'], 'RR');
select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed
select array_remove(array['X','X','X'], 'X') = '{}';
select array_replace(array[1,2,5,4],5,3); select array_replace(array[1,2,5,4],5,3);
select array_replace(array[1,2,5,4],5,NULL); select array_replace(array[1,2,5,4],5,NULL);
select array_replace(array[1,2,NULL,4,NULL],NULL,5); select array_replace(array[1,2,NULL,4,NULL],NULL,5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment