简体   繁体   中英

Python, SQLite3: How to insert a list of integers into a cell in the table

I have a list of integers with >2000 items and so I can't split each value into a column of its own due to the 2000 column limit for SQL:

a = [1, 0, 0, 1, 0,....]

and another str value

version = 'dog'

How should I be writing the code so that I can input the list, as is, into a single cell, possibly a BLOB type cell?

import sqlite3 as sql
con = sql.connect('test.db')
cur = con.cursor()
cur.execute("CREATE TABLE tablename(Version TEXT, A BLOB)")
cur.execute("CREATE INDEX Idx_Version ON tablename(Version)")

tuples = tuple([tuple(version, a)])
cur.execute('INSERT INTO tablename VALUES (?, ?)', tuples)

I'm fairly new to SQL and would appreciate any help I can get

>>list1 = [1, 2, 3]
>>string = ''.join([str(e) for e in list1])

>>string
'123'

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