MySQL: Get column name or alias from query

后端 未结 10 1768
死守一世寂寞
死守一世寂寞 2020-11-28 20:04

I\'m not asking for the SHOW COLUMNS command.

I want to create an application that works similarly to heidisql, where you can specify an SQL query and w

10条回答
  •  情歌与酒
    2020-11-28 20:40

    This is the same as thefreeman but more in pythonic way using list and dictionary comprehension

    columns = cursor.description 
    result = [{columns[index][0]:column for index, column in enumerate(value)} for value in cursor.fetchall()]
    
    pprint.pprint(result)
    

提交回复
热议问题