Re: understanding .description newbie ?

Tim Roberts <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization Providenza & Boekelheide, Inc.
Message-ID <[email protected]>
johnf wrote:
> Hi,
> dbapi 2.0 defines what a cursor.description returns.  In my case the 
> cursor.description returns {fieldName, someNumber, None,...}.  I would like 
> to better understand what the "someNumber" means.  How does python know 
> that '1043' is a varchar (python string??).
>   

Python doesn't.  Psycopg knows, because it knows the type codes that
Postgres uses.  Each database can use different codes.

If you want to use this info, you can say:

    if descr[i][1] in psycopg.STRING.values:
        pass # this is a string type
    elif descr[i][1] in psycopg.NUMBER.values:
        pass # this is a numeric type
    elif ...

Dbapi defines STRING, NUMBER, BINARY, DATETIME and ROWID.  Psycopg adds
DATE, TIME, FLOAT, INTERVAL, and LONGINTEGER.

-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.