Pull column names from query using JayDeBe & Redshift?

I am attempting to retrieve the column names after executing a query using JayDeBe. The current code I’m using is:

curs = conn.cursor()
curs.execute("select u.customer_name, u.status, from table.users u limit 10")
result = curs.fetchall()

I need to find a solution to return the column names, as the query may vary and a set format would not be suitable. I have searched online to find a solution, but have had no success. Any help on how to return the column names would be greatly appreciated.

You can retrieve the column names by calling the description attribute of the cursor object. Here’s the updated code:

curs = conn.cursor()
curs.execute("select u.customer_name, u.status, from table.users u limit 10")
result = curs.fetchall()
col_names = [desc[0] for desc in curs.description]
print(col_names)

This should print out the names of the columns (customer_name and status in this case) as a list.