Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get column names from query result using pymssql

Is there any way to get the column names from the pymssql results? If i specify as_dict=True I get back a dictionary, which does contain all the column headers, but since it is a dictionary they are not ordered.

like image 259
MK. Avatar asked Mar 04 '11 04:03

MK.


1 Answers

pymssql claims to support the Python DB-API, so you should be able to get the .description attribute from your cursor object.

.description

       This read-only attribute is a sequence of 7-item
       sequences.  

       Each of these sequences contains information describing
       one result column: 

         (name, 
          type_code, 
          display_size,
          internal_size, 
          precision, 
          scale, 
          null_ok)

So, the first item in each of the "inner" sequences is the name for each column.

like image 138
John Flatness Avatar answered Oct 05 '22 07:10

John Flatness