X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9A4FE32A1B5 for ; Sat, 16 Oct 2004 17:56:15 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11235-04 for ; Sat, 16 Oct 2004 16:56:10 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 217F732A15D for ; Sat, 16 Oct 2004 17:56:09 +0100 (BST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id i9GGu0fm027603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 16 Oct 2004 10:56:03 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id i9GGu0fF071935; Sat, 16 Oct 2004 10:56:00 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id i9GGu0ZH071934; Sat, 16 Oct 2004 10:56:00 -0600 (MDT) (envelope-from mfuhr) Date: Sat, 16 Oct 2004 10:56:00 -0600 From: Michael Fuhr To: Oliver Elphick Cc: pgsql-interfaces@postgresql.org Subject: Re: PL/Python: How do I use result methods? Message-ID: <20041016165600.GA71873@winnie.fuhr.org> References: <1097937269.12716.28.camel@linda> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1097937269.12716.28.camel@linda> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/21 X-Sequence-Number: 5116 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 exception set 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/