When I am using SQLALchemy how would one iterate through column names?
Eg.
Column Name 1, Column Name 2, Column Name 3, etc...
The second question is I have the following query:
root = dbsession.query(MyTable).filter(MyTable.name==u'john').all()
However, when I do:
for row in root:
print row
I don't get any results. Instead I have to do:
print row.name, row.age, etc...
Can't I just do print row
to return data from all the columns?
dbsession.query(MyTable).filter(MyTable.name==u'john')
will go through ORM and return you objects. If you just want to return all columns, you can bypass ORM with this:
query = dbsession.query(MyTable).filter(MyTable.name==u'john')
rows = query.statement.execute().fetchall()
for row in rows:
print row
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With