Home > Mobile >  cannot write to a snowflake table but with no errors returned
cannot write to a snowflake table but with no errors returned

Time:10-30

the code runs successfully with no errors returned, but only old records displayed:

import pandas as pd
from sqlalchemy import create_engine
from snowflake.sqlalchemy import URL
from config import config

engine = create_engine(URL(account=config.account, 
          user=config.username, 
          password=config.password, 
          warehouse=config.warehouse, 
          database=config.database, 
          schema=config.schema,))
    
conn = engine.connect()
    
df = pd.DataFrame([('AAA', '1234'), ('BBB', '5678')], columns=['name', 'pswd'])
df.to_sql('demo_db.public.test_f1', con=engine, index=False, if_exists='append', index_label=None)
        
df = pd.read_sql_query('select * from demo_db.public.test_f1', conn)
print(df.head(5))
    
conn.close()
engine.dispose()

Please help!

CodePudding user response:

It seems the 3 part name was treated as single identifier:

SELECT * FROM demo_db.public."demo_db.public.test_f1";

The name could be provided as:

df.to_sql('test_f1', con=engine, index=False, if_exists='append', index_label=None)
  • Related