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

0

2 Answers 2

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]
Sign up to request clarification or add additional context in comments.

4 Comments

Okay, that works so far but the all the values in the list have an L behind the value. So the list looks so now : ´[1L, 13L, 14L, 15L]´
Check this question: stackoverflow.com/q/11764713/244297 Generally, you shouldn't have to worry about it.
So what? That has no impact on anything.
Ah, okay now I got it. This L only shows that this are long values^^
0

cursor.fetchall() if you are using sqlalchemy.

1 Comment

Yes, but when I use ´(a,b,c,d, )=cursor.fetchall()´ I get values like (1L, ) with the datatype tuple

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.