jcmdogg
jcmdogg

Reputation: 25

how to specify delimiter when uploading csv onto snowflake using snowflake connector & COPY INTO function

I am uploading a csv file onto snowflake using the snowflake python connector. The CSV file needs to have a pipe delimiter. How can I specify this delimiter in the COPY INTO function?

conn = snowflake.connector.connect(
    user=os.environ.get("USER_NAME"),
    password=os.environ.get("PASSWORD"),
    account=os.environ.get("ACCOUNT"),
    warehouse=os.environ.get("WAREHOUSE"),
    database=os.environ.get("DATABASE"),
    schema=os.environ.get("SCHEMA"),
    role=os.environ.get("ROLE"))
conn.cursor().execute("PUT file://{} @%test)
conn.cursor().execute("COPY INTO test_table")
conn.cursor().close()

Upvotes: 0

Views: 1405

Answers (1)

Marcel
Marcel

Reputation: 2612

You have to use the parameter FIELD_DELIMITER = 'character'

Example in your case:

COPY INTO test_table file_format = (type=CSV FIELD_DELIMITER='|');
  

For more information and some other parameters you can have a look here: https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html

Upvotes: 1

Related Questions