Cannot access field in Big Query with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>>

SqlNestedGoogle Bigquery

Sql Problem Overview


I'm trying to run a query using Standard SQL Dialect (ie not Legacy SQL) on BigQuery. My query is:

SELECT
date, hits.referer
FROM `refresh.ga_sessions_xxxxxx*`
LIMIT 1000

But keep getting the error

Error: Cannot access field referer on a value with type 
ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [2:12]

Anyone know the proper syntax?

Sql Solutions


Solution 1 - Sql

if you are looking for all referers - try

SELECT date, h.referer
FROM `refresh.ga_sessions_xxxxxx*`, UNNEST(hits) as h

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFeynman27View Question on Stackoverflow
Solution 1 - SqlMikhail BerlyantView Answer on Stackoverflow