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 9E2A432A10E for ; Sat, 16 Oct 2004 15:34:38 +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 82997-03 for ; Sat, 16 Oct 2004 14:34:31 +0000 (GMT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id 7A43232A108 for ; Sat, 16 Oct 2004 15:34:34 +0100 (BST) Received: from lfix.demon.co.uk ([80.177.205.209] helo=cerberus.lfix.co.uk) by anchor-post-34.mail.demon.net with esmtp (Exim 4.42) id 1CIpdi-000CSQ-DU for pgsql-interfaces@postgresql.org; Sat, 16 Oct 2004 14:34:34 +0000 Received: from linda.lfix.co.uk ([192.168.1.1]) by cerberus.lfix.co.uk with esmtp (Exim 4.34) id 1CIpde-0001di-1y for pgsql-interfaces@postgresql.org; Sat, 16 Oct 2004 15:34:30 +0100 Subject: PL/Python: How do I use result methods? From: Oliver Elphick Reply-To: olly@lfix.co.uk To: pgsql-interfaces@postgresql.org Content-Type: text/plain Organization: LFIX Limited Message-Id: <1097937269.12716.28.camel@linda> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Sat, 16 Oct 2004 15:34:29 +0100 Content-Transfer-Encoding: 7bit X-LFIX-MailScanner: Found to be clean X-MailScanner-From: olly@lfix.co.uk 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/20 X-Sequence-Number: 5115 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@lfix.co.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