I do sampling from SQL

cur = db.cursor() cur.execute("SELECT FL_ARCHIVE FROM ROUTE WHERE FL_ARCHIVE >= 10") select_results = cur.fetchall() for result in select_results: print result 

Then for each sample element equal to ten for example, I want to run a specific function. The problem is that from the database I don’t return 10, but

 (10,) (10,) (11,) 

Of course, I understand that you can take a bite out of everything extra, but I guess I’m doing something wrong if this result is obtained.

By the way, is this 10 a string or a number? Those. I need to write

 if result == '10': 

or can:

 if result == 10: 

    1 answer 1

    You call fetchall (), so a tuple is returned to you. Cut on the first element.

     print result[0] 

    if result == '10': and if result == 10: different comparisons. Better before comparing lead to the expected type through str(result[0]) , for example. Though in your case the int type is returned.

    • So I seem to be walking through the tuple for for result in select_results: so everything should be fine ... And I still did not understand why my brackets appear superfluous when sampling ... - Dmitry Bubnenkov
    • cur.fetchall () always returns a tuple. - zzuz
    • SELECT FL_ARCHIVE * possibly returns a list. - zzuz