Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to understand what each field in the tuple returned from curs.description so I can know what the type is and parameters of that type.

See the code samples below. I basically will run some query and then print or manipulate the cursor description (which is a tuple). What does the data mean (I know one of the fields is the column name)? I want to understand what all these fields mean so I can parse any type information as needed.

for example, here is an SAP HANA query

select *
from "_NAMESPACE"."SomeTable"

which I run from python

conn01 = pyhdb.connect(host='', port=, user='', password = '')
curs02 = conn01.cursor()
curs02.execute(myQuery)
curs02.fetchone()
print(curs02.description) # prints tuple

Returns (for example):

(('FROM_SITE', 11, None, 1, 0, None, 2), ('TO_SITE', 11, None, 1, 0, None, 2), ('FROM', 11, None, 4, 0, None, 0), ('TO', 11, None, 4, 0, None, 0), ('TRX', 11, None, 2, 0, None, 0), ('ACCNUM', 11, None, 8, 0, None, 0), ('DESC', 11, None, 20, 0, None, 2), ('DMYNUM', 3, None, 10, 0, None, 0))

I would like to understand what all the fields within each tuple element is. For example, ('FROM_SITE', 11, None, 1, 0, None, 2). E.g., what is each field signify. "11" seems to signify varchar, but I don't understand all of these.

Thank you!! Is there a reference for what number for the type_code corresponds to what human readable type? From the link you shared, I see the names but not a cross-reference to a number. python.org/dev/peps/pep-0249/#type-objects – Brad d Sep 17, 2019 at 21:21 No. At one time I compiled a cross-reference table of the type_codes used by various DBMSs for different data types, and there is no consistency. Your best bet is to create a table with columns containing all data types (that you care about), query it, and inspect the type_code values that you get back. – rd_nielsen Sep 17, 2019 at 21:23

The type_code numbers returned by pyhdb are HANA specific. The number directly corresponds with the type code field returned by the HANA server in the network protocol. This number can change, depending on the client and server version, even if the corresponding column type appears the same.

A list of the known type_code numbers can be found in the pyhdb source code:

https://github.com/SAP/PyHDB/blob/master/pyhdb/protocol/constants/type_codes.py

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.