"OperationalError: no such column: " in python + sqlite3
Phenomenon
When I try to add data to the database using sqlite3 in python, I get "Operational Error: no such column: None".
It reproduce with the following code. Suppose the examples table has a column value of type integer. Store the value of the variable x created inside python as value.
The environment is python 3.7 sqlite 3.30.0
import sqlite3
db_path="test.sqlite3"
con=sqlite3.connect(db_path)
c=con.cursor()
x=1
sql="insert into examples(value) values({0})".format(x)
c.execute(sql)
con.commit()
con.close()
There is no problem with x = 1. However, if x = None,
OperationalError: no such column: None
Cause
Because I used .format (), "None" became a string. To be correct, write as follows. This was also officially recommended.
#~~~omit~~~~
x=None
sql="insert into examples(value) values(?)"
c.execute(sql, [x])
#~~~omit~~~~
Recent Posts
See AllSummary Data analysis is performed using python. The analysis itself is performed using pandas, and the final results are stored in pandas.DataFrame format. I want to output this result to a file in j
Phenomenon I get a title error when trying to import firestore with raspberry pi. from from firebase_admin import firestore ImportError: Failed to import the Cloud Firestore library for Python. Make s
Overview If you want to do fitting, you can do it with scipy.optimize.leastsq etc. in python. However, when doing fitting, there are many cases where you want to condition the fitting parameters. For