When reading an expression in a formal language, I'm used to reading from the inside out, i.e. understanding subexpressions and building up to the whole. In this SQL snippet:
SELECT
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'TITLE') AS level_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'url') AS url
FROM `events_20180725`
WHERE event_name = 'SCI_ERROR'
One subexpression is
SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'TITLE'
That's not a normal subquery: if I were to try to run it on its own, I would get an error because event_params isn't an array. So it seems that
UNNESTcan be used with something other than arrays.- There is some kind of binding of the table
events_20180725used in the outerFROMwhich makes it accessible to theUNNESTinside the subquery.
https://cloud.google.com/bigquery/docs/reference/standard-sql/arrays contains some examples (under 'Querying Nested Arrays'), but doesn't actually explain the semantics. What's going on here?