[英]Errors trying to copy data from a view into a table in snowflake
I am new to snowflake and I am trying to copy data from a view into an existing table我是雪花的新手,我正在尝试将数据从视图复制到现有表中
the below CTEs does some processes my data but when I try to copy the output view into a table I get Unexpected insert
下面的 CTE 对我的数据进行了一些处理,但是当我尝试将 output 视图复制到表中时,出现
Unexpected insert
with LD as(
select "ID",
"Value",
"Set",
ROW_NUMBER()OVER ( PARTITION BY "ID" order by "Set" desc ) as rownum
from "Archive"."Prty" l
where l."Prty" = 'Log' AND "ID"= 111
),
LD2 as (
select "ID",
"Value",
"Set",
ROWNUM
from LD where ROWNUM = 1
)
---- copy view into table -------
INSERT INTO "v1" ("ID", "Value","Set",ROWNUM )
SELECT * FROM LD2
After much research, I discovered that the insert statement should be at the top and select at the bottom经过多方研究,我发现insert语句应该在最上面,select在最下面
INSERT INTO "v1" ("ID", "Value","Set",ROWNUM )
with LD as(
select "ID",
"Value",
"Set",
ROW_NUMBER()OVER ( PARTITION BY "ID" order by "Set" desc ) as rownum
from "Archive"."Prty" l
where l."Prty" = 'Log' AND "ID"= 111
),
LD2 as (
select "ID",
"Value",
"Set",
ROWNUM
from LD where ROWNUM = 1
)
SELECT * FROM LD2
You answer is correct the reason is the instruction is您的回答是正确的,原因是说明是
INSERT INTO X SELECT
which is the same as这与
INSERT INTO X (SELECT)
and the WITH CLAUSE is a pre-fix to a SELECT, thus second form WITH CLAUSE 是 SELECT 的前缀,因此是第二种形式
INSERT INTO X (WITH y SELECT)
You can see this also happen with things like recursive CTE's which expect the first item to be the recursive CTE but if you want a "prior CTE" you end up having the form你可以看到这也发生在递归 CTE 之类的事情上,它期望第一项是递归 CTE,但如果你想要一个“先前的 CTE”,你最终会得到这样的形式
WITH cte_a as (
-- body of cte_a
), cte_b as(
WITH recursive_cte as(
-- body of recursive that uses cte_a
)
SELECT * FROM recursive_cte
)
SELECT * from cte_b
This is works, is somewhat ugly, but there we are, there are patterns that the parser expects, and they must be confirmed to.这是有效的,有点丑陋,但我们已经看到了解析器期望的模式,并且必须确认它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.