Is there any way I can insert dict data to a sqlite3 column?
Let's say I have a table named item
and I would like to insert co-ordinates like x and y which is a dict {'x': 2, 'y': 4}
to the column name called position
I have given the datatype of position
as varchar
or blob
.
In both cases it shows me
sqlite3.InterfaceError: Error binding parameter :position - probably unsupported type.
Is there any way I can insert value {'x': 2, 'y': 4}
to position
column? what is the best way to insert a dict?
EDIT
for i in range(0, count):
item = {
'player': random.choice(players),
'floor': random.choice(floors),
'position': {
'x': random.randint(0, 17),
'y': random.randint(0, 10)
},
'ts': random.randint(ts_2015_01_01, ts_now)
}
columns = ', '.join(item.keys())
placeholders = ':'+', :'.join(item.keys())
query = 'INSERT INTO items (%s) VALUES (%s)' % (columns, placeholders)
print(query)
c.execute(query, item)
connection.commit()
here c is the cursor based on connection
on my sqlite db.