Reputation: 43
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!
Upvotes: 4
Views: 651
Reputation: 175566
It seems the 3 part name was treated as single identifier and data was inserted into table called "demo_db.public.test_f1"
:
SELECT * FROM demo_db.public."demo_db.public.test_f1";
The name could be provided as table name only and database/schema are inferred from connection:
df.to_sql('test_f1', con=engine, index=False, if_exists='append', index_label=None)
Upvotes: 1