If the specified value is present in the designated ARRAY, the function returns TRUE.
Supported Datatypes, array
ARRAY_JOIN( <array_expr>, <value> )
Concatenates the elements of the array using the provided delimiter. If a Null replacement is defined, any Null values in the array are substituted with the specified Null replacement.
Supported Datatypes, array
ARRAY_SLICE( <array_expr>, <from_index>, <to> )
Returns an array constructed from a specified subset of elements of the input array.
Supported Datatypes, array
The output result comprises elements from the from index upto to parameter but excluding the element identified by the to parameter.
Array starts with index 1.
If array, from index or to parameter is NULL then the result is None
When either "from" or "to" is a negative value, it refers to the end of the array, not the beginning. For example, “0” denotes the last position in the array and "-2" denotes the third-to-last position in the array.
If both "from" and "to" exceed the upper limit of the array or fall below the lower limit of the array, the result will be an empty set.
FILTER_ARRAY( <array_expr> , <func>)
Filters the array in expr using func function.
Supported Datatypes, array
Lambda expressions in SQL enable users to efficiently create functions within SQL queries for manipulating array-based data. Specifically designed to handle nested data structures like arrays.
The function iterates through the elements of an array and applies the user-provided transformation or expression.
<func> should be a boolean expression
NOTE - Known limitations:
Aggregate functions are not supported in filter functions.
Lambda expressions are not supported in 'IN' clause.
UNNEST( <array_expr> )
UNNEST transforms an ARRAY into a table, generating a separate row for each element within the ARRAY.
> with cte as(
select 1 as id, 'a' as c1
union all
select 1 as id, 'a' as c1
union all
select 1 as id, 'b' as c1
union all
select 2 as id, 'b' as c1
union all
select 2 as id, 'b' as c1
)
select id,array_agg(distinct c1 )
from cte
group by 1
order by 1
1, [ "a", "b" ]
2, [ "b" ]
> select filter_array(array[10, null, 6, 7, null], x -> x is not null);
10, 6, 7
> SELECT * FROM UNNEST(ARRAY[10,20,30]) as numbers
|10
|20
|30
> WITH Sequences AS
(SELECT 1 AS id, array[0, 1, 1, 2, 3, 5] AS some_numbers
UNION ALL SELECT 2 AS id, array[2, 4, 8, 16, 32] AS some_numbers
UNION ALL SELECT 3 AS id, array[5, 10] AS some_numbers)
SELECT id, flattened_numbers
FROM Sequences
CROSS JOIN UNNEST(Sequences.some_numbers) AS flattened_numbers
order by 1,2;
|1 |0
|1 |1
|1 |1
|1 |2
|1 |3
|1 |5
|2 |2
|2 |4
|2 |8
|2 |16
|2 |32
|3 |5
|3 |10