Snowflake 中 LATERAL FLATTEN(...) 和 TABLE(FLATTEN(...)) 的区别

Difference between LATERAL FLATTEN(...) and TABLE(FLATTEN(...)) in Snowflake

在 Snowflake 中使用 LATERAL FLATTEN(...)TABLE(FLATTEN(...)) 有什么区别?我检查了 FLATTEN, LATERAL and TABLE 上的文档,无法确定以下查询之间的功能差异。

select
    id as account_id,
    account_regions.value::string as region
from
    salesforce.accounts,
    lateral flatten(split(salesforce.accounts.regions, ', ')) account_regions
select
    id as account_id,
    account_regions.value::string as region
from
    salesforce.accounts,
    table(flatten(split(salesforce.accounts.regions, ', '))) account_regions

我要说的是,在所提供的查询中没有区别 - 因为横向连接是通过动态创建 table 隐含的,该 table 是在来自一行的值内操作的结果。

真正需要 flatten 关键字的查询如下:

select * 
from departments as d
  , lateral (
    select * 
    from employees as e 
    where e.department_id = d.department_id
  ) as iv2
order by employee_id;
-- https://docs.snowflake.com/en/sql-reference/constructs/join-lateral.html

如果此联接没有 lateral 关键字,您将得到一个 Error: invalid identifier 'D.DEPARTMENT_ID'