Lists & arrays
Scalar
filter()
Constructs a list from those elements of the input list for which the lambda function returns true. DuckDB must be able to cast the lambda function's return type to BOOL. The return type of list_filter is the same as the input list's.
Alias of list_filter()
Arguments & returns
filter(list, lambda(x))
Scalar
| Overload link | list | lambda(x) |
Returns |
|---|---|---|---|
| #01 | ANY[] | LAMBDA |
ANY[] |
Example
Haybarn WASM 1.5.5-rc3 · In your browser
Engine example · Run to view results.
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)