How to reference anonymous columns?

Viewed 27

What would be the proper way to reference these columns from the unnest operation?

select PARSE_DATE('%Y-%m-%d', f0_) from unnest(["2014-01-01", "2015-01-01"])

f0_ which is the column display name is not reference-able it seems.

1 Answers

From the docs you can alias unnest:

For input ARRAYs of most element types, the output of UNNEST generally has one column. This single column has an optional alias, which you can use to refer to the column elsewhere in the query. ARRAYS with these element types return multiple columns

So you can call it like this:

SELECT PARSE_DATE('%Y-%m-%d', date) 
FROM unnest(["2014-01-01", "2015-01-01"]) AS date

enter image description here

Related