Skip to content

Commit 97c4d9b

Browse files
committed
Don't emit non-canonical empty arrays in array_remove().
Dean Rasheed
1 parent 01497e7 commit 97c4d9b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/backend/utils/adt/arrayfuncs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5398,6 +5398,14 @@ array_replace_internal(ArrayType *array,
53985398
return array;
53995399
}
54005400

5401+
/* If all elements were removed return an empty array */
5402+
if (nresult == 0)
5403+
{
5404+
pfree(values);
5405+
pfree(nulls);
5406+
return construct_empty_array(element_type);
5407+
}
5408+
54015409
/* Allocate and initialize the result array */
54025410
if (hasnulls)
54035411
{

src/test/regress/expected/arrays.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,12 @@ select array_remove(array['A','CC','D','C','RR'], 'RR');
15771577

15781578
select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed
15791579
ERROR: removing elements from multidimensional arrays is not supported
1580+
select array_remove(array['X','X','X'], 'X') = '{}';
1581+
?column?
1582+
----------
1583+
t
1584+
(1 row)
1585+
15801586
select array_replace(array[1,2,5,4],5,3);
15811587
array_replace
15821588
---------------

src/test/regress/sql/arrays.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ select array_remove(array[1,2,2,3], 5);
438438
select array_remove(array[1,NULL,NULL,3], NULL);
439439
select array_remove(array['A','CC','D','C','RR'], 'RR');
440440
select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed
441+
select array_remove(array['X','X','X'], 'X') = '{}';
441442
select array_replace(array[1,2,5,4],5,3);
442443
select array_replace(array[1,2,5,4],5,NULL);
443444
select array_replace(array[1,2,NULL,4,NULL],NULL,5);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy