简体   繁体   中英

DELETE FROM doesn't work in Python for SQL

I want to delete all rows in my tables that are empty. But the same command I use in SQL doesnt work in Python. Its on my raspberry and im using SQLite3.

I dont get any error message doing:

import sqlite3

currency_pairs = ['AUDUSD', 'EURCHF', 'EURUSD', 'EURCAD']

conn = sqlite3.connect("/home/ken/database/database.db")
cursor = conn.cursor()

for c in currency_pairs:
        cursor.execute("DELETE FROM {c} WHERE Close IS NULL;".format(c=c))

conn.close()

Again, using DELETE FROM AUDUSD WHERE Close IS NULL; for example works in my sqlite3 programm.

I think you need to use conn.commit() when executing one or multiple delete statement(s). Committing is not necessary if you select.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM