0
我有以下代碼插入文件名Postgres的表稱爲「日誌」插入文件名Postgres的表
c = engine.connect()
conn = c.connection
cur = conn.cursor()
cur.execute("SELECT filename from logs")
rows1 = cur.fetchall()
rows1 = [x[0] for x in rows1]
for root, directories, filenames in os.walk(path):
for filename in filenames:
fname = os.path.join(root,filename)
if os.path.isfile(fname) and fname[-4:] == '.log':
if fname not in rows1:
print fname
cur.execute(""" INSERT INTO logs(filename) VALUES (%(fname)s)""")
conn.commit()
我收到錯誤
ProgrammingError: syntax error at or near "%"
LINE 1: INSERT INTO logs(filename) VALUES (%(fname)s)
我可以知道在哪裏我做錯了?
這有效..謝謝Daniel – ckp