SQL 编译错误:位置 157 的语法错误第 5 行意外'<EOF>'
Posted
技术标签:
【中文标题】SQL 编译错误:位置 157 的语法错误第 5 行意外\'<EOF>\'【英文标题】: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)
【问题讨论】:
【参考方案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
【讨论】:
以上是关于SQL 编译错误:位置 157 的语法错误第 5 行意外'<EOF>'的主要内容,如果未能解决你的问题,请参考以下文章
Snowflake SQL 编译错误:位置 XX 处的语法错误行 XX 意外 '('
通过 JTDS 驱动程序执行 SQL Server 调用时出现“第 24 行位置的 JDBC 转义语法无效 '=' 预期字符”错误的原因?