module for working with the result set

john fabiani jfabiani at yolo.com
Mon May 17 19:03:22 EDT 2004


Diez B. Roggisch wrote:
>>mydata=cursor.fetchmany(10)
>>for field in mydata[0]:
>>   print mydata[0][field]
>>
>>Traceback (most recent call last):
>>   File "C:\Python23\Lib\site-packages\sm\scriptutils.py", line 49, in run
>>     exec codeObject in mainDict
>>   File "<source>", line 10, in ?
>>   File "C:\Python23\Lib\site-packages\pyPgSQL\PgSQL.py", line 2063, in
>>__getitem__
>>     key = self._xlatkey[key.lower()]
>>KeyError: '5992      '
>>Exception raised while running script  <source>
>>
>>But ;(
>>print mydata[0][0], mydata[0][1]
>>the above works perfectly - prints what I want.
> 
> 
> it seems that the value of field is 5992, and that isn't a key to the row -
> which is quite likely, as 5992 as column-name is most probably forbidden,
> and as index a little bit high - can't imagine what a table with ~6000
> columns should hold....
> 
> Now what about showing us the result of this:
> 
> mydata=cursor.fetchmany(10) 
> print mydata[0]
> 
> Then one can tell how to access  the fields. Thats a general advice: when
> such things occur, print out the values in question short before the
> problem, then you can see if and more important why what you expect and
> what you get differ.
>
See this does not make sense to me.


mydata[0]
['5992      ', 'A', '5346      ', '                              ', 'XX 
        ', 'Kathy Stromme                 ', 'RICHMOND AMERICAN HOMES 
               ', '7250 WEST PEAK, ST # 212                ', ' 
                                ', 'LAS VEGAS           ', 'NEVADA 
    ', '89128     ', '                         ', '702-240-5600 
', '                              ', 'RICHMOND AMERICAN HOMES 
       ', '7250 WEST PEAK, ST # 212                ', ' 
                        ', 'LAS VEGAS           ', 'NEVADA         ', 
'89128     ', '                         ', '702-240-5600        ', ' 
                           ', '          ', '          ', ' 
        ', '          ', '          ', '          ', '          ', ' 
       ', '0/0/30    ', 'FIRST     ', '                    ', ' 
            ', '     ', '                              ', ' 
        ', 'USD', '          ', <DateTime object for '2004-01-16 
00:00:00.00' at 1779820>, <DateTime object for '2004-02-06 00:00:00.00' 
at 17590e0>, <PgBoolean instance at 01EBB580: Value: False>, <PgBoolean 
instance at 01EBB580: Value: False>, <PgBoolean instance at 01EBB580: 
Value: False>, <PgBoolean instance at 01EBB580: Value: False>, 
<PgBoolean instance at 01EBB580: Value: False>, <PgBoolean instance at 
01EBB580: Value: False>, <PgBoolean instance at 01EBB580: Value: False>, 
<PgBoolean instance at 01EBB580: Value: False>, <PgBoolean instance at 
01EBB580: Value: False>, <PgBoolean instance at 01EBB580: Value: False>, 
<PgBoolean instance at 01EBB580: Value: False>, <PgNumeric instance - 
precision: 3 scale: 0 value: 0>, <PgNumeric instance - precision: 3 
scale: 0 value: 30>, <PgNumeric instance - precision: 6 scale: 2 value: 
0.00>, <PgNumeric instance - precision: 6 scale: 2 value: 0.00>, 
<PgNumeric instance - precision: 8 scale: 5 value: 0.00000>, <PgNumeric 
instance - precision: 8 scale: 5 value: 0.00000>, <PgNumeric instance - 
precision: 8 scale: 5 value: 0.00000>, <PgNumeric instance - precision: 
14 scale: 2 value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 
value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 value: 0.00>, 
<PgNumeric instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric 
instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - 
precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - precision: 14 
scale: 2 value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 
value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 value: 0.00>, 
<PgNumeric instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric 
instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - 
precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - precision: 14 
scale: 2 value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 
value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 value: 0.00>, 
<PgNumeric instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric 
instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - 
precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - precision: 14 
scale: 6 value: 1.000000>, <PgNumeric instance - precision: 14 scale: 2 
value: 0.00>, <PgNumeric instance - precision: 14 scale: 2 value: 0.00>, 
<PgNumeric instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric 
instance - precision: 14 scale: 2 value: 0.00>, <PgNumeric instance - 
precision: 14 scale: 2 value: 0.00>, '', '', '64          ', '    ', 
'4-PPPP-34      ', 'COURTYARD @ LONE MT. TERRACE  ', '          ', 'RACL 
', '                                                                 ', 
'R1', '               ', 'ALVJU', 'MONJO', <PgNumeric instance - 
precision: 2 scale: 0 value: 30>, <PgNumeric instance - precision: 7 
scale: 2 value: 36.48>, <PgNumeric instance - precision: 5 scale: 2 
value: 25.00>, <PgNumeric instance - precision: 5 scale: 2 value: 0.00>, 
<PgNumeric instance - precision: 7 scale: 2 value: 14.42>, <PgNumeric 
instance - precision: 5 scale: 2 value: 0.00>, <PgNumeric instance - 
precision: 5 scale: 2 value: 0.00>, None, None, None, <PgNumeric 
instance - precision: 5 scale: 2 value: 2.30>, None, <PgNumeric instance 
- precision: 10 scale: 2 value: 317.00>, <PgNumeric instance - 
precision: 10 scale: 1 value: 5346.4>, 'JUAN ALVAREZ 
                   ', 'JOSE MONTALVO 
  ', '          ', '5992      ', '          ', None, None, <PgNumeric 
instance - precision: 7 scale: 2 value: 0.00>, <PgNumeric instance - 
precision: 7 scale: 2 value: 0.00>, None, None, ' 
                            ', ' 
           ', None, None, None, None, <PgBoolean instance at 01EBB580: 
Value: False>, '          ', <DateTime object for '2004-02-12 
00:00:00.00' at 1759060>, '                                   ', None, 
None, None, '                    ', None, <PgBoolean instance at 
01EBB580: Value: False>]



More information about the Python-list mailing list