[Tutor] cursor.description

Tim Golden Tim.Golden at viacom-outdoor.co.uk
Fri Nov 24 17:18:47 CET 2006


[Antonios Katsikadamos]

| Hi all. I am new to python and i am trying to execute queries 
| from postgres db. I have a question.
|  
| What is exactly the operation of cursor.description?

Ultimately, the doc you want to look at is this:

http://www.python.org/dev/peps/pep-0249/

Here's the relevant bit:

"""
.description 
          
            This read-only attribute is a sequence of 7-item
            sequences.  Each of these sequences contains information
            describing one result column: (name, type_code,
            display_size, internal_size, precision, scale,
            null_ok). The first two items (name and type_code) are
            mandatory, the other five are optional and must be set to
            None if meaningfull values are not provided.

            This attribute will be None for operations that
            do not return rows or if the cursor has not had an
            operation invoked via the executeXXX() method yet.
            
            The type_code can be interpreted by comparing it to the
            Type Objects specified in the section below.
"""

In practise, this means that, once a cursor's executed, you
can read the names/types of columns returned from the description
tuple.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Tutor mailing list