Snowflake中
LATERAL FLATTEN(...)
和TABLE(FLATTEN(...))
的使用有什么区别?我检查了有关 FLATTEN
、LATERAL
和 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
我会说,在所提供的查询中没有区别 - 因为横向联接是通过在来自行的值内操作的结果动态创建表来隐含的。
对
lateral
关键字的真正需求来自于这样的查询:
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'
。