0
votes

following the documentation for SQL String composition, I want to execute a DELETE statement in my postgresql database:

db_cursor.execute(sql.SQL("DELETE FROM {}".format(sql.Identifier(table_name))))

This results in the error:

File "try_pandas.py", line 189, in _store_in_table
db_cursor.execute(sql.SQL("DELETE FROM {}".format(sql.Identifier(table_name))))
psycopg2.ProgrammingError: syntax error at or near "("
LINE 1: DELETE FROM Identifier('fixture_identification')

Another, similar execute is working fine:

db_cursor.copy_expert(sql.SQL("COPY {} FROM STDIN WITH CSV HEADER").format(sql.Identifier(table_name)), table_file)

I really don't see the difference...

1

1 Answers

0
votes

The difference is here:

sql.SQL("DELETE FROM {}".format())

It should be

sql.SQL("DELETE FROM {}").format() # Notice the brackets.