How to retrieve SQL result column value using column name in Python?

后端 未结 10 1107
闹比i
闹比i 2020-11-27 14:05

Is there a way to retrieve SQL result column value using column name instead of column index in Python? I\'m using Python 3 with mySQL. The syntax I\'m looking for is pretty

10条回答
  •  隐瞒了意图╮
    2020-11-27 14:56

    import mysql.connector as mysql
    ...
    cursor = mysql.cnx.cursor()
    cursor.execute('select max(id) max_id from ids')
    (id) = [ id for id in cursor ]
    

提交回复
热议问题