To get the column headings you can use the cursor's description attribute which returns the metadata of the results and is described here.
Use it like the following:
import snowflake.connector
import os
snowflake_username = os.environ['SNOWFLAKE_USERNAME']
snowflake_password = os.environ['SNOWFLAKE_PASSWORD']
snowflake_account = os.environ['SNOWFLAKE_ACCOUNT']
snowflake_warehouse = os.environ['SNOWFLAKE_WAREHOUSE']
snowflake_database = 'sample_data'
snowflake_schema = 'tpch_sf1'
if __name__ == '__main__':
with snowflake.connector.connect(
user=snowflake_username,
password=snowflake_password,
account=snowflake_account,
warehouse=snowflake_warehouse,
database=snowflake_database,
schema=snowflake_schema,
autocommit=False
) as con:
# Execute cursor and print metadata
cursor = con.cursor().execute("select * from sample_data.TPCH_SF1.customer limit 10")
for c in cursor.description:
print(c)
# # Fetch and print results
# results = cursor.fetchall()
# print(results)
The above prints out:
('C_CUSTKEY', 0, None, None, 38, 0, False)
('C_NAME', 2, None, 25, None, None, False)
('C_ADDRESS', 2, None, 40, None, None, False)
('C_NATIONKEY', 0, None, None, 38, 0, False)
('C_PHONE', 2, None, 15, None, None, False)
('C_ACCTBAL', 0, None, None, 12, 2, False)
('C_MKTSEGMENT', 2, None, 10, None, None, True)
('C_COMMENT', 2, None, 117, None, None, True)