简体   繁体   English

复制到<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

I am trying to copy data to snowflake from local and I am getting我正在尝试将数据从本地复制到雪花,我得到了

snowflake.connector.errors.ProgrammingError: 001757 (42601): SQL compilation error: Table 'RAW_DATA' does not exist snowflake.connector.errors.ProgrammingError: 001757 (42601): SQL 编译错误:表 'RAW_DATA' 不存在

the same code is working in Jupiter notebook but it doesn't work in vs code.相同的代码在 Jupiter notebook 中有效,但在 vs code 中无效。 My role is accountadmin so no issue with the permissions.我的角色是 accountadmin,所以权限没有问题。

Code I am trying to run is this我要运行的代码是这个

COPY INTO RAW_DATA file_format=(FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)

I suspect you are using a different Database/schema than the Jupiter notebook我怀疑您使用的数据库/模式与 Jupiter 笔记本不同

select current_warehouse(), current_database(), current_schema();

for me gives:对我来说:

Try replacing 'TABLE' with your table name.尝试用您的表名替换“TABLE”。

Example:例子:

COPY INTO mytable FROM 's3://mybucket/./../a.csv';

There is a syntax error.存在语法错误。 You cannot name use TABLE as a table name.您不能命名使用TABLE作为表名。 TABLE is a reserved keyword https://docs.snowflake.com/en/sql-reference/reserved-keywords.html TABLE是保留关键字https://docs.snowflake.com/en/sql-reference/reserved-keywords.html

From the docs: https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html来自文档: https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html

COPY INTO [<namespace>.]<table_name>
     FROM { internalStage | externalStage | externalLocation }
[ FILES = ( '<file_name>' [ , '<file_name>' ] [ , ... ] ) ]
[ PATTERN = '<regex_pattern>' ]
[ FILE_FORMAT = ( { FORMAT_NAME = '[<namespace>.]<file_format_name>' |
                    TYPE = { CSV | JSON | AVRO | ORC | PARQUET | XML } [ formatTypeOptions ] } ) ]
[ copyOptions ]
[ VALIDATION_MODE = RETURN_<n>_ROWS | RETURN_ERRORS | RETURN_ALL_ERRORS ]

So instead of所以而不是

COPY INTO TABLE FILE_FORMAT = (FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)

try尝试

 COPY INTO MYTABLE FILE_FORMAT = (FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)

Of course you will need to create MYTABLE first.当然,您需要先创建MYTABLE

It was not working with它没有与

COPY INTO RAW_DATA file_format=(FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)

But Then I tried但后来我尝试了

table_name = "RAW_DATA"
f"COPY INTO {table_name} file_format=(FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)"

it started working.它开始工作了。 Not sure why but this seems working for now不知道为什么,但这似乎现在有效

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM