On Sat, Oct 16, 2004 at 03:34:29PM +0100, Oliver Elphick wrote:
>
> 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)
The documentation describes nrows as being a method of the result
object, so I'd guess it should be used thusly:
n = arec.nrows()
I tried that with the following function:
CREATE OR REPLACE FUNCTION test() RETURNS INTEGER AS $$ rv = plpy.execute('SELECT usename FROM pg_user') n =
rv.nrows()return 1 $$ LANGUAGE plpythonu;
The function failed:
test=> SELECT test(); ERROR: plpython: function "test" failed DETAIL: exceptions.SystemError: error return without
exceptionset
Digging through plpython.c I discovered the following:
#ifdef NOT_USED /* Appear to be unused */ static PyMethodDef PLy_result_methods[] = { {"fetch", (PyCFunction)
PLy_result_fetch,METH_VARARGS, NULL,}, {"nrows", (PyCFunction) PLy_result_nrows, METH_VARARGS, NULL},
{"status",(PyCFunction) PLy_result_status, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; #endif
It looks like nrows(), status(), and fetch() aren't available as
result object methods. I don't know what would happen if you
un-#ifdef-ed that block and the two others that are related;
perhaps one of the developers can tell us what's going on.
If the methods aren't available then they probably shouldn't be
mentioned in the doc.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/