PL/Python: How do I use result methods?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: PL/Python: How do I use result methods?
Date: 2004-10-16 14:34:29
Message-ID: 1097937269.12716.28.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-interfaces

I'm having my first try at a PL/Python function. It is also a first try
at Python, so the answer to this may be obvious.

According to the docs (8.0):

Calling plpy.execute with a query string and an optional limit
argument causes that query to be run and the result to be
returned in a result object. The result object emulates a list
or dictionary object. The result object can be accessed by row
number and column name. It has these additional methods: nrows
which returns the number of rows returned by the query, and
status which is the SPI_execute() return value.

What exactly is the syntax for using the nrows and status methods?

I am trying to use it like this:

...
arec = plpy.execute(plan, [ addrno ], 1)
plpy.info("Executed plan")
n = plpy.nrows(arec)
plpy.info(" got nrows")
...

This gives the output:
advacs=# select core.formatted_address(1);
INFO: ('Prepared plan',)
INFO: ('Executed plan',)
ERROR: plpython: function "formatted_address" failed
DETAIL: exceptions.AttributeError: 'module' object has no attribute 'nrows'

If I use
n = arec.nrows

the message becomes
DETAIL: exceptions.SystemError: error return without exception set

so how do you use it?

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"But be ye doers of the word, and not hearers only,
deceiving your own selves." James 1:22

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-10-16 16:20:19 Re: Why we still see some reports of "could not access
Previous Message Neil Conway 2004-10-16 13:45:12 Re: Why we still see some reports of "could not access

Browse pgsql-interfaces by date

  From Date Subject
Next Message Michael Fuhr 2004-10-16 16:56:00 Re: PL/Python: How do I use result methods?
Previous Message Tomasz Myrta 2004-10-11 15:58:57 Re: PGacces