【问题标题】:SQL compilation error: syntax error line 5 at position 157 unexpected '<EOF>'SQL 编译错误:位置 157 的语法错误第 5 行意外'<EOF>'
【发布时间】:2020-08-28 01:22:04
【问题描述】:

这里可能有什么问题??

create or replace temp table Whse_Role_Spend as
with 
Warehouse_Spend as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name from 
"SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name),
Role_Spend as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name, role_name from 
"SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name, role_name),
Credits_Used as (select sum(Credits_used) Credits_Used, warehouse_name from 
"SNOWFLAKE"."ACCOUNT_USAGE"."WAREHOUSE_METERING_HISTORY" group by warehouse_name)

【问题讨论】:

    标签: sql syntax-error snowflake-cloud-data-platform


    【解决方案1】:

    它给出了 EOF 错误,因为有一个没有 CTE 查询的 CTE 定义。编译器在找到 CTE 查询之前到达语句的结尾,因此它返回 EOF 错误。

    CTE 定义还需要在表表达式上定义列。您需要加入这些表,但是您希望它们在 CTE 查询中(最后)。这应该可以让您摆脱 EOF 问题,并接近您可以按照您想要的方式完成语句的位置。

    create or replace temp table Whse_Role_Spend as
    with 
        Warehouse_Spend(total_elapsed, warehouse_name) as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name from 
            "SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name),
        Role_Spend (Total_Elapsed, warehouse_name, role_name) as (select sum(total_elapsed_time) Total_Elapsed, warehouse_name, role_name from 
            "SNOWFLAKE"."ACCOUNT_USAGE"."QUERY_HISTORY" group by warehouse_name, role_name),
        -- Add column definitions on the next table expression similar to the ones above.
        Credits_Used as (select sum(Credits_used) Credits_Used, warehouse_name from 
            "SNOWFLAKE"."ACCOUNT_USAGE"."WAREHOUSE_METERING_HISTORY" group by warehouse_name)
    select s.total_elapsed, 
           s.warehouse_name
    from WAREHOUSE_SPEND S, ROLE_SPEND R; -- Join the CTE tables as you need them
    

    【讨论】:

      猜你喜欢
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多