how to get column names in native python client hp_vertica_client

Does anyone know if the python client they provide
https://my.vertica.com/docs/8.1.x/HTML/python_client/index.html
is able to fetch the column names for a given query programmatically?

Thanks.

Comments

  • Colin, Yes the Python client can give you the number of columns retrieved in a query as well as the description of these columns

    Say you execute this query

    cursor.execute("SELECT first_name, avg, ops FROM foo WHERE avg > 0.225")

    cursor.columns will return 3
    cursor.description will return the description (including name) of these 3 columns

  • Excellent,
    Here is how to get the column names from the active cursor
    headers = [desc[0] for desc in cur.description ]
    Thanks Serge. The documentation is quite dry on this topic, but i see the cursor attributes mentioned.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file