SQLAlchemy syntax error when TRUNCATE TABLE

34 views Asked by At

TRUNCATE TABLE my_table gives me syntax error from SQLAlchemy. I have seen other issues where the commit didn't occur, but this isn't the case.

I really have no troubles with executing other queries on the same table such as DROP or SELECT, but TRUNCATE gives:

>>> with engine.begin() as con:
>>>
>>>     statement = text("TRUNCATE TABLE my_table")
>>> 
>>>     con.execute(statement)

sqlite3.OperationalError: near "TRUNCATE": syntax error

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "TRUNCATE": syntax error
[SQL: TRUNCATE TABLE my_table]

The table name is something I can access from sqlalchemy.inspect(engine) as well, and that I can operate on with other query operations.

I have Postgres, SQLAlchemy v2.0.23.

0

There are 0 answers