【问题标题】:Difference between LATERAL FLATTEN(...) and TABLE(FLATTEN(...)) in Snowflake雪花中 LATERAL FLATTEN(...) 和 TABLE(FLATTEN(...)) 之间的区别
【发布时间】:2021-03-14 23:27:23
【问题描述】:

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

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】:

    我会说,在呈现的查询中没有区别 - 因为横向连接是隐含的动态创建表,该表是根据对一行中的值进行操作的结果来动态创建的。

    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'

    【讨论】:

      猜你喜欢
      • 2015-01-16
      • 2018-08-24
      • 2019-12-05
      • 2015-05-04
      • 2015-05-09
      • 1970-01-01
      相关资源
      最近更新 更多