Inconsistent behavior when using sqlite3.Row to index results by name

In my Python application, I use sqlite3.Row as the factory string to index the results by name for some time without any problems. I recently moved the application to a new server (no code changes), and I found that this indexing method now unexpectedly fails on the new server, given a rather specific condition. I do not see any explanation.

The problem occurs on a new server when there is a keyword in my select request DISTINCT:

import sqlite3
conn = sqlite3.connect(':memory:')
conn.row_factory = sqlite3.Row
c = conn.cursor()

c.execute('create table test ([name] text)')
c.execute("insert into test values ('testing')")
conn.commit()

c.execute('select [name] from test')
row = c.fetchone()
print row['name'] # works fine on both machines

c.execute('select distinct [name] from test') # add distinct keyword
row = c.fetchone()
print row['name'] # fails on new server (no item with that key)

, , , . Debian (: Ubuntu 8.10, : Debian 5.0.3), Python 2.5.2. , sqlite3 Python, , , python .

- - - ?

,

+3
2

print row.keys()

"print row ['name']", , 0 (, "DISTINCT" ).

[0] , , .:)

+1

, , Google "indexerror no item with the key" . , sqlite - row_factory = sqlite3.Row. sqlite 3.24.0 :

select table.col
from table

... , col. , table.col. - . :

select table.col as "col"
from table

:

select col
from table
0

Source: https://habr.com/ru/post/1766800/


All Articles