Home > other >  Bigquery - Return array of structs with specific fields of the struct
Bigquery - Return array of structs with specific fields of the struct

Time:11-01

I have an array of structs in bigquery. I would like to return an array of structs, but the struct of the array with less fields that the original struct.

Example:

enter image description here

I would like to have the same results but without Skills.Id.

I tried to do something like this but

  SELECT  [(select struct(dd.Level as Level, dd.TypeId as typeid)
                  from unnest(dd.Skills) as dd  )]  as skills    
   FROM tablee dd

But get an exception:

Scalar subquery produced more than one element

CodePudding user response:

Try ARRAY instead of []:

SELECT ARRAY(select struct(dd.Level as Level, dd.TypeId as typeid) 
             from unnest(tablee.Skills) as dd) as skills    
FROM tablee
  • Related