简体   繁体   English

Python,SQLite3:如何在表的单元格中插入整数列表

[英]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: 我有一个包含> 2000个项目的整数列表,因此由于SQL的2000列限制,我无法将每个值拆分成自己的列:

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

and another str value 和另一个str值

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? 我应该如何编写代码,以便可以将列表按原样输入单个单元格(可能是BLOB类型的单元格)中?

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 我对SQL还是很陌生,希望能得到我的任何帮助

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

>>string
'123'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM