如何在sqlalchemy中做这样的事情?

时间:2016-06-01 10:19:03

标签: sqlalchemy

假设:

class Users(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String)

我怎么能在sqlalchemy中这样做:

select id,username,0 as deleted from users

其中deleted不在users

1 个答案:

答案 0 :(得分:0)

您可以使用sqlalchemy.sql.expression.literal

from sqlalchemy.sql.expression import literal
db.session.query(User.id, User.username, literal(0).label('deleted'))