I am having an issue when I select data from the SQL database through pyodbc where I end up with this type of result.
[(55.0, )]
I want the pure number (no "[" or "(" so I later can insert it into a different table after calculating new stuff with it. I am sure it's trivial but I just haven't been able to figure out how. Below is the code I am using:
rows = conn.execute("SELECT price from PG").fetchall()
print(rows[:1])
You have [(55.0, )]
because you have a list of rows (containing a single row in this example), and each row is a tuple (with a single element, since you just selected price
). You can do
singlerow = rows[0]
price, = singlerow
However, fetching all rows to select just one seems weird, you should probably re-think your query.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments