How to get a list from query in sqlalchemy

python, sql, sqlalchemy

Solution

I use (in @classmethod - that's why cls instance here; I also have added 'session' to class properties=)

list(session.query(cls))

returns exactly the simple list of all DeclarativeBase's instances.

Problem

when I do the following in python using sqlalchemy `someVar = self.session.query(sometable.someVar).group_by(sometable.someVar).all()` I get a list of one variable tuples like `[(var1,), (var2,), ..]` Is there a way of getting a flat list within sqlalchemy. I know how to flatten the list of tuple within python code, but that solution is bit clumsy. I am just wondering if this is possible. My goal is to get a list of distinct entries someVar from sometable.

Original source

Related problems