简体   繁体   English

尝试将数据从视图复制到雪花表中时出错

[英]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.这是有效的,有点丑陋,但我们已经看到了解析器期望的模式,并且必须确认它们。

复制到<div id="text_translate"><p>我正在尝试将数据从本地复制到雪花,我得到了</p><blockquote><p> snowflake.connector.errors.ProgrammingError: 001757 (42601): SQL 编译错误:表 'RAW_DATA' 不存在</p></blockquote><p>相同的代码在 Jupiter notebook 中有效,但在 vs code 中无效。 我的角色是 accountadmin,所以权限没有问题。</p><p> 我要运行的代码是这个</p><pre>COPY INTO RAW_DATA file_format=(FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)</pre></div>在雪花抛出表中不存在<table> </table> - COPY INTO <table> in snowflake throws table does not exist

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 雪花视图:尝试从另一个表连接数据时超出最大 LOB 大小错误 - Snowflake View: Max LOB size exceeded error while trying to join data from another table 将数据从视图复制到表 - Copy data from view to a table Snowflake:如何在涉及约束和默认值的情况下执行 CTAS 或将数据从表 x 复制到 y? - Snowflake: How to perform CTAS or copy data from table x to y with constraints and default values involved? 如何将镶木地板文件从 Azure Blob 存储复制到雪花表中? - How to copy parquet file from Azure Blob Storage into Snowflake table? COPY INTO 带有额外列的雪花表 - COPY INTO Snowflake Table with Extra Columns 将数据从2表复制到1表 - copy data from 2 table to 1 table 复制到<div id="text_translate"><p>我正在尝试将数据从本地复制到雪花,我得到了</p><blockquote><p> snowflake.connector.errors.ProgrammingError: 001757 (42601): SQL 编译错误:表 'RAW_DATA' 不存在</p></blockquote><p>相同的代码在 Jupiter notebook 中有效,但在 vs code 中无效。 我的角色是 accountadmin,所以权限没有问题。</p><p> 我要运行的代码是这个</p><pre>COPY INTO RAW_DATA file_format=(FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)</pre></div>在雪花抛出表中不存在<table> </table> - COPY INTO <table> in snowflake throws table does not exist 来自 CSV 的雪花 COPY INTO 列 - Snowflake COPY INTO column from CSV 尝试将数据从Impala Parquet表复制到非Parquet表 - Trying to copy data from Impala Parquet table to a non-parquet table 通过在 Snowflake 中传播来自 JSON 的数据来创建表格视图 - Create tabular View by Spreading Data from JSON in Snowflake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM