Can I get strings from SQLAlchemy that are simple arrays, not dictionaries?

I am trying to optimize Python code. The profiler tells me that SQLAlchemy _get_col () is what kills performance. The code looks something like this:

lots_of_rows = get_lots_of_rows()
for row in lots_of_rows:
    if row.x == row.y:
        print row.z

I was going to go through the code and make it more like this ...

lots_of_rows = get_lots_of_rows()
for row in lots_of_rows:
    if row[0] == row[1]:
        print row[2]

... but I found some documentation that seems to indicate that when accessing string objects, such as arrays, you actually still pull out the dictionary keys. In other words, the string object is as follows:

'x': (x object)
'0': (x object)
'y': (y object)
'1': (y object)
'z': (z object)
'2': (z object)

, , , . SA , ? , - - ?

+3
4

, row.x == row.y? :

mytable.select().where(mytable.c.x==mytable.c.y)

. .

+2

, row.items() - , . (, ) .

+1

SQLAlchemy . , . , , , ResultProxy RowProxy .

, 5US . , . dbapi. , SQLQlchemy . , , dbapi ResultProxy, result.cursor.cursor. (result.cursor - SQLAlchemy CursorFairy). dbapi fetchall(), fetchone() fetchmany().

, , , . , , .

+1

, "_get_col", , _get_col . ( _get_col ).

sqlalchemy, , lookup_key ( engine/base.py), , , , ( PopulateDict).

, .__ ( , ), , row.cursor, , , sqlalchemy ( sql) w/.

- J

0

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


All Articles