Reputation: 139
I am trying to load a csv file names F58155 to a table with the same name in snowflake. I have the file in csv format. And it is giving me the error in the title. I am also attaching the screenshot of the csv file line 178 where I am facing the issue(the rightmost column at the end). Can someone help?
import snowflake.connector
tableName='F58155'
ctx = snowflake.connector.connect(
user='*',
password='*',
account='*')
cs = ctx.cursor()
ctx.cursor().execute("USE DATABASE STORE_PROFILE_LANDING")
ctx.cursor().execute("USE SCHEMA PUBLIC")
ctx.cursor().execute("PUT file:///tmp/data/{tableName}/* @%{tableName}".format(tableName=tableName))
ctx.cursor().execute("truncate table {tableName}".format(tableName=tableName))
ctx.cursor().execute("COPY INTO {tableName} ".format(tableName=tableName))
ctx.close()
Upvotes: 0
Views: 1477
Reputation: 6802
It sounds like you might have a cell value that includes a comma. Something like:
1,2,3,"foo,bar",5,6
The COPY INTO statement has a FILE_FORMAT argument that you may want to experiment with to fit the nuances of your particular CSV file. For example, specifying...
FIELD_OPTIONALLY_ENCLOSED_BY = '"'
... would help with the above example of a comma inside a cell value, but there could also be escaping issues, newline issues, etc that might produce the same error.
Docs are here: https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html
Another suggestion is to examine the CSV file with a text editor like VS Code that would help you spot something odd/unique about the row throwing the error. The problem might also be on the previous line.
Good luck!
Upvotes: 3