Getting COUNT from sqlalchemy

前端 未结 3 897
闹比i
闹比i 2020-12-11 06:02

I have:

res = db.engine.execute(\'select count(id) from sometable\')

The returned object is sqlalchemy.engine.result.ResultProxy

3条回答
  •  遥遥无期
    2020-12-11 06:21

    what you are asking for called unpacking, ResultProxy is an iterable, so we can do

    # there will be single record
    record, = db.engine.execute('select count(id) from sometable')
    # this record consist of single value
    count, = record
    

提交回复
热议问题