Database & utility
Scalar
filter()
Constructs a list from those elements of the input list for which the lambda function returns true
Reference: DuckDB 1.3.2
Alias of list_filter()
Arguments & returns
filter(list, lambda)
Scalar
| Overload link | list | lambda |
Returns |
|---|---|---|---|
| #01 | ANY[] | LAMBDA |
ANY[] |
Example
Haybarn WASM 2.0.0-rc12 ยท In your browser
Engine example ยท Run to view results.
Catalog examples
SELECT
list_filter([3, 4, 5], x -> x > 4);
In other engines
Used in larger rewrites 5
These examples use filter as one part of a larger SQL translation.
PostgreSQL
SELECT CORR(a, b) FILTER(WHERE c > 0)
SELECT CORR(a, b) FILTER(WHERE c > 0)
Apache Hivecollect_list()
COLLECT_LIST(x)
ARRAY_AGG(x) FILTER(WHERE x IS NOT NULL)
Apache Sparkcollect_set()
SELECT COLLECT_SET(sample_col) FROM sample_table
SELECT LIST(DISTINCT sample_col) FILTER(WHERE NOT sample_col IS NULL) FROM sample_table
BigQueryarray_agg()
SELECT ARRAY_AGG(x IGNORE NULLS) AS x
SELECT ARRAY_AGG(x) FILTER(WHERE x IS NOT NULL) AS x
Snowflakearray_agg()
SELECT ARRAY_AGG(DISTINCT a)
SELECT ARRAY_AGG(DISTINCT a) FILTER(WHERE a IS NOT NULL)