1
File "/home/user/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 2712, in to_sql
    method=method,
File "/home/user/.local/lib/python3.6/site-packages/pandas/io/sql.py", line 498, in to_sql
    raise ValueError("'{0}' is not valid for if_exists".format(if_exists))
ValueError: 'tableName' is not valid for if_exists

That's the error I get when I'm trying to ingest data into a postgres table through sqlalchemy. It worked before, but recently it's not going through. Here's the code that prompted the error:

data.to_sql(tableName,
            engine=db.create_engine(self.dbString),
            if_exists='replace',
            schema='public')

I can ingest the data into a new table, but that new table is also unable to be dropped with another ingestion attempt with if_exist='replace'.

Is there a permission problem or another problem? I tried changing the connection string to login as superuser postgres will all the permissions and that didn't change anything. The default user I'm using has all the permissions except RLS.

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
R. Gao
  • 23
  • 4
  • 1
    The stacktrace does not look like SQLAlchemy's, but rather like pandas's. – 9000 Feb 26 '20 at 04:22
  • Not sure what you mean, but I don't understand why it (sqlalchemy or pandas) is not letting me replace existing tables with the if_exists method – R. Gao Mar 10 '20 at 11:33

0 Answers0