Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Sqlite3 order by on integer不工作(即使使用索引)_Python_Sqlite_Sql Order By - Fatal编程技术网

Python Sqlite3 order by on integer不工作(即使使用索引)

Python Sqlite3 order by on integer不工作(即使使用索引),python,sqlite,sql-order-by,Python,Sqlite,Sql Order By,Hy 有人能给我解释一下吗 sqlite> .schema LastFM CREATE TABLE LastFM(id INTEGER PRIMARY KEY, AlbumTitle TEXT, Hoerer INTEGER); CREATE INDEX Hoerer_Index ON LastFM( Hoerer DESC ); sqlite> Explain SELECT * FROM LastFM ORDER BY Hoerer; addr opcode

Hy

有人能给我解释一下吗

sqlite> .schema LastFM
CREATE TABLE LastFM(id INTEGER PRIMARY KEY, AlbumTitle TEXT, Hoerer INTEGER);
CREATE INDEX Hoerer_Index ON LastFM( Hoerer DESC );
sqlite> Explain SELECT * FROM LastFM ORDER BY Hoerer;
addr        opcode      p1          p2          p3          p4          p5
----------  ----------  ----------  ----------  ----------  ----------  ---------
0           Trace       0           0           0                       00
1           Noop        0           0           0                       00
2           Goto        0           16          0                       00
3           OpenRead    0           6           0           3           00
4           OpenRead    2           9           0           keyinfo(1,  00
5           Rewind      2           13          1           0           00
6           IdxRowid    2           1           0                       00
7           Seek        0           1           0                       00
8           IdxRowid    2           2           0                       00
9           Column      0           1           3                       00
10          Column      2           0           4                       00
11          ResultRow   2           3           0                       00
12          Next        2           6           0                       00
13          Close       0           0           0                       00
14          Close       2           0           0                       00
15          Halt        0           0           0                       00
16          Transactio  0           0           0                       00
17          VerifyCook  0           4           0                       00
18          TableLock   0           6           0           LastFM      00
19          Goto        0           3           0                       00
sqlite> SELECT * FROM LastFM ORDER BY Hoerer;
id          AlbumTitle    Hoerer
----------  ------------  ----------
35          Live In Oslo  1
36          Kleine Welt   1
37          The Land Of   1
38          No Limit / R  1
39          Faust... In   1
40          Live At Last  1
41          2009-10-10:   1
42          Collectif Me  1
13          Bbc Sessions  128
14          From Glory T  128
3           So Far        1294
27          Schiphorst 2  15
28          Od Serca Do   15
12          Faust / So F  178
32          The Wumme Ye  2
33          The Faust Co  2
我有一个表LastFmid整数主键,AlbumTitle文本,Hoerer整数 并用python从csv文件中填充数据:

reader = csv.reader(open(csvFileName, 'r'), delimiter=';') for row in reader: to_db = [] for col in row: to_db.append(unicode(col, "utf8")) cur.execute("INSERT INTO LastFM(AlbumTitle, Hoerer) VALUES (?, ?);", to_db) sqlConnection.commit() 但“按顺序”功能无法正常工作。 我已经尝试在我不想排序的列上创建索引,但它也不起作用


一些提示?

您已经在Hoerer列中插入了字符串,这就是字符串的排序方式


如果要在此列中包含数字,则导入代码必须插入数字。

问题在于您设法将数据作为文本或BLOB插入。如果可能,文本应转换为整数,但BLOB不能转换。作为短期修复,您可以通过Casthoeer将其作为整数进行订购,这是从sqlite_master选择sql的输出,其中name=LastFM,type=table?sqlite>SELECT sql FROM sqlite_master,其中name=LastFM,type=table;sql-创建表LastFMid INTEGER主键,AlbumTitle文本,Hoerer INTEGERI不理解。我已经将表列Hoerer定义为整数。这就是为什么我认为我添加到Hoerer列中的所有内容都保持为整数。如果不能转换成整数,我会得到一个错误。那么,如果csv文件数据看起来像:一些文本;123