简体   繁体   中英

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

the same code is working in Jupiter notebook but it doesn't work in vs code. My role is accountadmin so no issue with the permissions.

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

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

for me gives:

Try replacing 'TABLE' with your table name.

Example:

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

There is a syntax error. You cannot name use TABLE as a table name. TABLE is a reserved keyword 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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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