Single column query results in a list of tuples in SQLAlchemy
- sqlalchemy
- tuple
The question is about why a simple single column query such as
>>> results = session.query(MyModel.id).all()
results in a list of tuples of id (and/or what to do about it):
>>> results
[(1,), (2,), (3,), (4,)]
instead of a list of ids. A simple solution is to iterate over the results and
use unpacking:
>>> [value for value, in results]
[1, 2, 3, 4]