Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active September 30, 2016 07:38
Show Gist options
  • Save yancya/53c8a0816c3de9ac4fc49fca436700d4 to your computer and use it in GitHub Desktop.
Save yancya/53c8a0816c3de9ac4fc49fca436700d4 to your computer and use it in GitHub Desktop.
BigQuery の Standard SQL で Legacy SQL の FLATTEN(table_name) 相当の処理を行う SQL
WITH t AS (
SELECT *
FROM UNNEST(ARRAY<STRUCT<id INT64, `names` ARRAY<STRING>>>
[(1, ['A', 'B']), (2, ['A']), (3, ['A'])]))
SELECT t.id
, `name`
FROM t
JOIN UNNEST(t.`names`) AS `name`
ORDER BY 1, 2
Row id name
1 1 A
2 1 B
3 2 A
4 3 A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment