The Vertica Forum recently got a makeover! Let us know what you think by filling out this short, anonymous survey.
Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

how to get column names in native python client hp_vertica_client

Does anyone know if the python client they provide
is able to fetch the column names for a given query programmatically?



  • SergeBSergeB - Select Field - Employee

    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
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file