I have a dict like this:
{
'05_23': '[L]',
'05_22': '9:39',
'05_21': '9:37',
'05_20': '9:34',
'05_27': '14:41'
}
I take the keys and values from it and create lists:
keys = list(d.keys())
print keys
['05_23', '05_22', '05_21', '05_20', '05_27']
values = list(d.values())
print values
['[L]', '9:39', '9:37', '9:34', '14:41']
And then I construct this SQL query with it:
c.execute("INSERT INTO table {} VALUES {}".format(tuple(keys), tuple(values)))
Which results in the following error:
c.execute("INSERT INTO table {} VALUES {}".format(tuple(keys), tuple(values)))
sqlite3.OperationalError: near "table": syntax error
And I can't figure out how to make it work.
asked Jun 24, 2015 at 11:26
Faryus
1611 gold badge4 silver badges14 bronze badges
1 Answer 1
table is not a valid table name. See the list of SQLite keywords.
The SQL standard specifies a huge number of keywords which may not be used as the names of tables, ...
answered Jun 24, 2015 at 11:30
user1907906
Sign up to request clarification or add additional context in comments.
1 Comment
Faryus
Wow... that didn't occur to me. It works fine now. Thanks!
default
tableis a SQL keyword. You want the table name there.INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);you need to replace table_name with the name of your tablec.execute("INSERT INTO table_name (X) VALUES (:X)", d)