top of page

"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 All

[Python] Output pandas.DataFrame as json

Summary 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

[Python] Conditionally fitting

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

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Inquiries: Please contact us on Twitter

  • Twitter
bottom of page