Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 575 Bytes

transforming-arrays.md

File metadata and controls

26 lines (19 loc) · 575 Bytes

Transforming arrays

Explore this snippet here.

Description

To transform elements of an array (often known as mapping over an array), it is possible to gain access to array elements using the UNNEST function:

with data as (select [1,2,3] nums, ['a', 'b', 'c'] strs)

select

  array(
    select
      x * 2 + 1 -- Transformation function
    from unnest(nums) as x
  ) as nums_transformed,

  array(
    select
      x || '_2' -- Transformation function
    from unnest(strs) as x
  ) as strs_transformed
  
from data