Python 为什么psycopg2“是什么;删除“;导致编程错误?

Python 为什么psycopg2“是什么;删除“;导致编程错误?,python,postgresql,psycopg2,Python,Postgresql,Psycopg2,根据的文档,我想在postgresql数据库中执行DELETE语句: db_cursor.execute(sql.SQL("DELETE FROM {}".format(sql.Identifier(table_name)))) 这将导致以下错误: File "try_pandas.py", line 189, in _store_in_table db_cursor.execute(sql.SQL("DELETE FROM {}".format(sql.Identifier(table_na

根据的文档,我想在postgresql数据库中执行DELETE语句:

db_cursor.execute(sql.SQL("DELETE FROM {}".format(sql.Identifier(table_name))))
这将导致以下错误:

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')
另一方面,类似的execute工作正常:

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

我真的看不出有什么区别…

区别在于:

sql.SQL("DELETE FROM {}".format())
应该是

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

我曾经是盲人,但现在我明白了。。。谢谢:)