-
TLDR; Maybe the README needs an example of setting output-format with the connection, I am seriously lost here I'm just starting to incorporate this client into some orchestrated python jobs, and after hours of searching I cannot find how to return column headers with the results dataset. Only the default CSV output format seems to be available. I'm just doing the quickstart example from the README. Example result: from trino.dbapi import connect
from trino.auth import BasicAuthentication
conn = connect(
host="my-trino-host-prod.net",
port=443,
user="user",
auth=BasicAuthentication(user, password)
)
cur = conn.cursor()
cur.execute("SELECT * FROM hive.warehouse.my_table")
rows = cur.fetchall()
rows
[['2022-09-18', 'PAGEVIEWS', 298953628], ['2022-09-18', 'Visits', 169684510], ['2022-09-18', 'WidgetClicks', 317498]] I'm sure there is a way to get column header row with the result, but I'm pretty sure that requires setting a property in the connection. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
OK -- I'm a python noob and probably most experienced python users would be able to figure out there is a Cursor field member that has the column headings, via trial and error. I suggest this note gets added to the quickstart guide on README. cur.description
[('week_end', 'date', None, None, None, None, None), ('metric_name', 'varchar', None, None, None, None, None), ('metric_value', 'bigint', None, None, None, None, None)] I think the way to know this would be inspecting the cursor object: dir(cur)
['__class__', '__delattr__', '__dict__', ... 'connection', 'description', 'execute', 'executemany', 'fetchall', 'fetchmany', 'fetchone', 'genall', 'info_uri', 'rowcount', 'setinputsizes', 'setoutputsize', 'stats', 'update_type', 'warnings']
# and then go through the available fields to discover that 'description' has the column names |
Beta Was this translation helpful? Give feedback.
OK -- I'm a python noob and probably most experienced python users would be able to figure out there is a Cursor field member that has the column headings, via trial and error.
I suggest this note gets added to the quickstart guide on README.
I think the way to know this would be inspecting the cursor object: