excelman
excelman

Reputation: 419

SQLAlchemy Teradata - Unable to use the df.to_sql functionality

I am attempting to use SQLAlchemy to load data from a pandas dataframe into a Teradata database table using the pandas.to_sql method.

import sqlalchemy as sa

username = "my_username"
password = "my_password"
hostname = "hostname"

database = "database"
table_name = "database.table"

teradata_engine = sa.create_engine(f"teradatasql://{hostname}/?user={username}&password={password}")

df.to_sql(name=table_name, con=teradata_engine, if_exists='append', index=False)

When attempting to use the pandas.to_sql method, I get below error.

sqlalchemy.exc.OperationalError: (teradatasql.OperationalError) [Version 20.0.0.20] [Session 23332535] [Teradata Database] [Error 3524] The user does not have CREATE TABLE access to database my_username.

Only suggestions that I could find related to this were from this post, suggesting:

You can work on this by either using another user or defining the "--TargetWorkingDatabase" parameter.

Since I am using python, I understand this to be the database parameter which I added:

teradata_engine = sa.create_engine(f"teradatasql://{hostname}/?user={username}&password={password}?database={database}")

But after doing this I am getting a username and password error, which goes away once I remove the database parameter.

sqlalchemy.exc.OperationalError: (teradatasql.OperationalError) [Version 20.0.0.20] [Session 23330616] [Teradata Database] [Error 8017] The UserId, Password or Account is invalid.

I am wondering what else to try. Any suggestions would be really appreciated.

Upvotes: 0

Views: 56

Answers (0)

Related Questions