BigQuery unnest multiple params

Viewed 30

I need to unnest multiple param keys event_date, page_location,page_title,user_pseudo_id. Two of them, page_location and page_title I need to unnest and show them separately. The code below just randomly shows either the location or title value, I need them in a separate row

SELECT
 event_date, value.string_value, user_pseudo_id, 
FROM
  ` mydata.events20220909*`, 
    unnest(event_params)
WHERE
key = "page_title" OR key = "page_location"
1 Answers

You don't necessarily have to unnest all the event_params, with the following query, you can put any parameter in a separate column

select
  event_date,
  user_pseudo_id, 
  (select value.string_value from unnest(event_params) where key = 'page_location') as page_location,
  (select value.string_value from unnest(event_params) where key = 'page_title') as page_title
from `mydata.events_20220909*`

Related