You want array_contains():
where array_contains('cats'::variant, column2)
Answer from Gordon Linoff on Stack OverflowSnowflake Documentation
docs.snowflake.com › en › sql-reference › functions › filter
FILTER | Snowflake Documentation
Filters an array based on the logic in a lambda expression.
Top answer 1 of 3
8
You want array_contains():
where array_contains('cats'::variant, column2)
2 of 3
3
ARRAY_CONTAINS() works, but you have to be careful with types.
For example, this one returns false:
select array_contains('2020-01-01'::date::variant
, array_construct('2020-01-01', '2019-01-01'));
But these return true:
select array_contains('2020-01-01'::date::string::variant
, array_construct('2020-01-01', '2019-01-01'));
select array_contains('2020-01-01'::date::variant
, array_construct('2020-01-01'::date, '2019-01-01'));
In the case of strings, this one returns a compilation error (as you saw):
select array_contains('cats'
, array_construct('cats', 'dogs'));
-- SQL compilation error: error line 1 at position 7 Invalid argument types for function 'ARRAY_CONTAINS': (VARCHAR(4), ARRAY)
But this one fixes it:
select array_contains('cats'::variant
, array_construct('cats', 'dogs'));
Videos
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › array_except
ARRAY_EXCEPT | Snowflake Documentation
This function returns an ARRAY that contains the elements from source_array that are not in array_of_elements_to_exclude.
DataSunrise
datasunrise.com › home › simplify data analysis in snowflake with the filter function
Snowflake FILTER | Knowledge Center
May 20, 2025 - The result is an array containing only the elements that satisfy the condition. The return type of data in the SELECT statement is identical to the input data type used in the FILTER function. Lambda expressions in Snowflake are a useful tool that lets users create and use unnamed functions ...
Reddit
reddit.com › r/sql › snowflake: can we filter out dates from a list?
r/SQL on Reddit: Snowflake: can we filter out dates from a list?
July 21, 2023 -
Hi everyone,
This one is giving me a hard time...
Is anyone able to filter a list of dates?
Example:
I have the array below:
select array_construct( '2023-05-06', '2023-05-08', '2023-05-09', '2023-05-13', '2023-05-15', '2023-05-16', '2023-05-17') as my_array
I would like to filter out the dates that are (strictly) before '2023-05-10': ['2023-05-13', '2023-05-15', '2023-05-16', '2023-05-17']
Considerations
I do not need to worry about duplicate values, it will always be unique dates.
Dates will also be sorted.
The date parameter I will use to filter out is not always part of the array.
Any help is appreciated, thank you! and happy Friday :)
Top answer 1 of 2
3
You can flatten the array and query it. Then reaggregate the filtered list of values as an array. with arr as ( select array_construct('2023-05-06', '2023-05-08', '2023-05-09', '2023-05-13', '2023-05-15', '2023-05-16', '2023-05-17') as my_array ), flat as ( select array_agg(value::date) as dts from arr ,lateral flatten(input => my_array) where value::date > '2023-05-09' ) select * from flat Result: [ "2023-05-13", "2023-05-15", "2023-05-16", "2023-05-17" ]
2 of 2
1
I was able to solve this by creating a UDF function in Javascript as a workaround: CREATE OR REPLACE FUNCTION {{ db }}.{{ schema }}.DATE_ARRAY_FILTER(date_array ARRAY, date_filter DATE, is_after BOOLEAN, is_strict BOOLEAN) RETURNS ARRAY LANGUAGE JAVASCRIPT AS $$ var filteredDates = []; var filterDate = new Date(DATE_FILTER); for (var i = 0; i < DATE_ARRAY.length; i++) { var dateVal = new Date(DATE_ARRAY[i]); if ((IS_AFTER && dateVal > filterDate) || (!IS_AFTER && dateVal < filterDate) || (!IS_STRICT && dateVal.getTime() === filterDate.getTime())) { filteredDates.push(dateVal.toISOString().split('T')[0]); } } return filteredDates; $$; Would prefer using standard SQL but I am sharing in case somebody else is interested
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › array_contains
ARRAY_CONTAINS | Snowflake Documentation
Returns TRUE if the specified value is found in the specified array.
Snowflake Community
community.snowflake.com › s › question › 0D50Z00007Dg44ASAR › how-to-filter-by-tags-in-array-when-using-json
How to filter by tags in array when using JSON
Join our community of data professionals to learn, connect, share and innovate together
Y42
y42.com › learn › snowflake › array_contains
Snowflake ARRAY_CONTAINS | How-to Guide with Examples | Y42 Learning hub
Learn how to use Snowflake’s ARRAY_CONTAINS function to check for the presence of a value within an array. Includes syntax details, usage notes, and practical examples for array search operations.
Snowflake Community
community.snowflake.com › 0D5VI00000DghjT0AR
Snowflake Community
Join our community of data professionals to learn, connect, share and innovate together
Medium
medium.com › snowflake › making-the-most-of-filters-in-snowflake-cortex-search-1d4c03b05ed3
Making the Most of Filters in Snowflake Cortex Search | by James Cha-Earley | Snowflake Builders Blog: Data Engineers, App Developers, AI, & Data Science | Medium
March 6, 2025 - CREATE CORTEX SEARCH SERVICE mysvc ON transcript_text -- The text column to search ATTRIBUTES region, agent_id, tags -- Columns you can filter on WAREHOUSE = mywh TARGET_LAG = '1 hour' AS ( SELECT transcript_text, date, region, agent_id, tags -- This would be an ARRAY type column FROM support_db.public.transcripts_etl ); With this setup, all the columns listed in the ATTRIBUTES clause become available for filtering in your search queries. When using Snowflake’s Cortex Search, you interact with it through a search service API.
Reddit
reddit.com › r/snowflake › [video] new in snowflake sql: filter and transform (and to tell you all about it, i wrote this song)
r/snowflake on Reddit: [video] New in Snowflake SQL: FILTER and TRANSFORM (and to tell you all about it, I wrote this song)
September 5, 2023 - Is it just me or are queries on snowflake quite slow? My team is running something as simple as (eg: select ... from activity where task_id = '.....' ) which fetches around 1 million rows and the query takes up to around 30plus seconds. We fetch only 8 fields + use material view.
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › array_remove
ARRAY_REMOVE | Snowflake Documentation
An ARRAY with all elements equal to the specified value removed.



