tags:

views:

504

answers:

1

In one of my django views I query database using plain sql (not orm) and return results.

sql = "select * from foo_bar"
cursor = connection.cursor()
cursor.execute(sql)
rows = cursor.fetchall()

I am getting the data fine, but not the column names. How can I get the field names of the result set that is returned?

+3  A: 

According to PEP 249, you can try using cursor.description, but this is not entirely reliable.

Ignacio Vazquez-Abrams
Thanks, this is exactly what I needed.