'Trying to DELETE FROM <Table> using SQLAlchemy

Trying to DELETE FROM using SQLAlchemy. Error is sqlalchemy.exc.ArgumentError: subject table for an INSERT, UPDATE or DELETE expected, got 'organization'.

organization is the name of the table I am trying to delete from.

This for a utility that takes a list of tables from one database instance and copying the rows to another database instance--but I want the target table to be empty--the user logged in is not an admin so can't do a TRUNCATE. If there is a better way, I'm open. Thanks.

Calling code stub:

for item in table_list:
    process_tbl(engine_in, engine_out, item["table"])

called function:

def process_tbl(engine_in, engine_out, table):
    pd = pandas.read_sql(table, engine_in)
    print(pd.columns)

    stmt = delete(table)
    print(stmt)

    rows = pd.to_sql(table, engine_out, if_exists="append", index=False)
    print("Table: " + table + " inserted rows: " + str(rows))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source