I have a table with many columns —
class Dummy(object):
__tablename__ = 'dummies'
c1 = Column(Integer)
c2 = Column(Integer)
c3 = Column(Integer)
...
cN = Column(Integer)
Can I query through all columns individually without specifying each column name manually? —
for i in range(1, N):
c_name = 'c%d' % i
dummy = DBSession().query(Dummy).filter_by(???=0).first()
Thanks.
You can iterate over the columns in a table. First, the table:
and finally, the query
Or maybe, you actually are generating a specific set of columns from a more elaborate function than you’re showing. In which case, use
getattr. No, really.