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

问题描述 投票:0回答:1

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
snowflake-cloud-data-platform flatten lateral-join
1个回答
5
投票

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

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'

© www.soinside.com 2019 - 2024. All rights reserved.