I perform this kind of query in my Python code to
conn = rdbms.connect(instance=_INSTANCE_NAME, database='tiger')
cursor = conn.cursor()
cursor.execute("SELECT * from terminals")
rows = cursor.fetchall()
After this I call a Jinja2 template, to which I pass the rows variable, which I can successullfy use there in a {% for row in rows %} code.
I could not find out how I can get the name of the columns. I tried to get it out of the rows variable, but in vain. Any idea?
After you execute your SQL query, try reading from the property
cursor.descriptionWith the MySQLdb module (not sure if you can use that specific module with Google Cloud-SQL), the
.descriptionwill be a tuple of tuples, like ((field1_name, …), (field2_name, …), …)I hope that solves your problem. Best wishes for your project and happy coding!