Select specific column value with sqlalchamey based on filter

flask, flask-sqlalchemy, mysql, python, sqlalchemy

Solution

Pretty sure

`user = User.query.filter(User.username == currentuser).email`

does not actually execute the query, you have to do something like

`user = User.query.filter(User.username == currentuser).first().email`

as per http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.first

Note, the statement above will fail if the user doesn't exist as first() will return None.

Problem

Been messing around with SQLalchemy and Flask and have run up into a problem that I can't find good documentation on. I need to query for the email of a specific user, but I can't figure the right combination of filter and select the specific column. I've tried: ``` user = User.query.filter(User.username == currentuser).email user = User.query(User.email).filter(User.username == currentuser) user = User.query.filter(User.username == currentuser, User.email) user = User.query.filter(User.email, User.username == currentuser) ``` But I'm not able to get the results I want.

Original source