I am learning Snowflake right now, and the way FLATTEN() works is a bit counter intuitive.
A simple query.
SELECT
raw:first_name::STRING AS FName,
raw:last_name::STRING AS LName,
f.value::STRING AS Skill
FROM tbl,
TABLE(FLATTEN(raw:Skills)) f
ORDER BY raw:id::INT
LIMIT 5;
Elegantly, it flattens the Skills array and returns this.
| FNAME | LNAME | SKILL |
|---|---|---|
| Flossy | Fasson | PS3 |
| Flossy | Fasson | Vlookup |
| Flossy | Fasson | Go |
| Celeste | Hubert | Tcl-Tk |
| Celeste | Hubert | Zines |
My questions are:
Does Snowflake just infer that the source of
raw:Skillsis tabletbl, as table name is not explicitly expressed here?How does Snowflake align the array (as the right table) to the left table? It looks like a Cross Join with no join keys, if so, every array should be joined to each and every row on the left and result in incorrect alignment.
Related: Lateral Join