krishna kishore
krishna kishore

Reputation: 114

I am trying to load data into redshift using pandas and sqlalchemy

when i try to load first time pandas able to create the table and load into that, but second time it throwing error like Relation "mytablename" already exists

df = pd.read_csv("data.csv",sep = "|")
conn = create_engine('redshift+psycopg2://uname:[email protected]
1.redshift.amazonaws.com:5439/db')
df.to_sql("my table name",con = conn,if_exists = "append",index = False)

sqlalchemy.version = '1.1.9' pandas.version = '0.20.3'

Upvotes: 2

Views: 1177

Answers (1)

Rahul Gupta
Rahul Gupta

Reputation: 1802

You have to pass sqlalchemy engine not the connection object. Try this,

df = pd.read_csv('data.csv',sep = '|')
conn = create_engine('redshift+psycopg2://uname:[email protected]
1.redshift.amazonaws.com:5439/db')
df.to_sql('my table name', conn, if_exists = 'append',index = False)

If I’ve made a bad assumption please comment and I’ll refocus my answer.

Upvotes: 1

Related Questions