Column types with DB API

Thomas Robitaille thomas.robitaille at
Sun Jun 28 17:00:46 EDT 2009


I'm trying to use DB API compliant database modules
(psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to
determine the type of each column in a table. The DB API defines
cursor.description which contains information about the column names and
types (once .execute() has been used to select part or all of the table),
but the types are expressed as integers. I realize that these numbers can be
checked against the type objects such as MySQLdb.NUMBER to determine whether
a given column is a number, a date, text, etc. However, is there any way to
determine what the sub-type of a column is, for example if a column is a
NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or
real number?

Thanks in advance for any advice,

View this message in context:
Sent from the Python - python-list mailing list archive at

More information about the Python-list mailing list