簡體   English   中英

為什么psycopg2“ DELETE”會導致編程錯誤?

[英]Why does psycopg2 “DELETE” result in a programming error?

按照SQL String組成的文檔,我想在我的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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM