Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARRAY_REMOVE() in Snowflake?

Postgresql has the ARRAY_REMOVE function to remove elements from an array. How can I do this in Snowflake?

like image 613
Felipe Hoffa Avatar asked Oct 26 '25 09:10

Felipe Hoffa


2 Answers

Snowflake has this function ARRAY_REMOVE()

like image 194
Adrian White Avatar answered Oct 27 '25 23:10

Adrian White


It is possible to remove elements from ARRAY using either by element ARRAY_REMOVE or element's position ARRAY_REMOVE_AT:

SHOW BUILTIN FUNCTIONS LIKE 'ARRAY_REMOVE%';
name arguments
ARRAY_REMOVE ARRAY_REMOVE(ARRAY, VARIANT) RETURN ARRAY
ARRAY_REMOVE_AT ARRAY_REMOVE_AT(ARRAY, NUMBER) RETURN ARRAY

Usage:

SELECT ARRAY_REMOVE(['a', 'b', 'c'], 'b'::VARIANT);
-- [   "a",   "c" ]

SELECT ARRAY_REMOVE_AT(['a', 'b', 'c'], 1);
-- [   "a",   "c" ]

Output:

enter image description here

like image 33
Lukasz Szozda Avatar answered Oct 27 '25 21:10

Lukasz Szozda