I am trying to upload a DataFrame to snowflake through write_pandas. I have the database created, but when I try to upload the datafram, I get table not found error.
Please explain me why the code does not locate the table.
'''
from snowflake.connector.pandas_tools import write_pandas
conn = sf.connect(user=snow_username, password=snow_password, account=snow_account, wharehouse=snow_wharehouse, database= database, schema=schema)
cur = conn.cursor()
query = f"Use Database {database}"
cur.execute(query)
channel_name = "testdeb"
query = (f'''CREATE TABLE IF NOT EXISTS {channel_name} (
sepal_length INTEGER,
sepal_width INTEGER NOT NULL,
petal_length INTEGER NOT NULL,
petal_widht INTEGER NOT NULL)
''')
cur.execute(query)
success, nchunks, nrows, _ = write_pandas(conn, test_df, channel_name)
'''
Error: ProgrammingError: 001757 (42601): SQL compilation error: Table '"testdeb"' does not exist
I am able upload dataset into Snowflake with SQLalchemy not sure whats wrong with the above code.
conn_string = f"snowflake://{snow_username}:{snow_password}@{snow_account}/{snow_database}/{snow_schema}?warehouse={snow_wharehouse}"
engine = create_engine(conn_string)
connection = engine.connect()
if_exists = 'replace'
with engine.connect() as con:
test_df.to_sql(name=channel_name.lower(), con=con, if_exists=if_exists,index=False)