0

I get from my DB the following return, when I use the sql command SELECT DISTINCT RezeptID FROM Rezepte;:

((1L,), (13L,), (14L,), (15L,))

Now I want to work with this values. Normally I use for single values something like this:

a=cursor.execute(sql_command)
(a, )=cursor.fetchone()

But then I get of course only the first value, the "1" back. How can I work with all these values? It would be optimal when I can put all these values in a array

codeforester
  • 39,467
  • 16
  • 112
  • 140
jofri
  • 131
  • 1
  • 16

2 Answers2

2

A cursor can be used as an iterator to iterate over rows in the result set. To get the first value from each row try this:

cursor.execute(sql)
values = [row[0] for row in cursor]
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
0

cursor.fetchall() if you are using sqlalchemy.

CK Chen
  • 625
  • 5
  • 15
  • Yes, but when I use ´(a,b,c,d, )=cursor.fetchall()´ I get values like (1L, ) with the datatype tuple – jofri Apr 28 '17 at 08:32