pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: pgsql-interfaces@postgresql.org
Subject: PL/Python: How do I use result methods?
Date: Sat, 16 Oct 2004 15:34:29 +0100
Message-ID: <1097937269.12716.28.camel@linda> (raw)

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 




view thread (6+ messages)  latest in thread

Message-ID: <1097937269.12716.28.camel@linda>
Permalink:  ../1097937269.12716.28.camel@linda/
Also on:    postgresql.org/message-id/1097937269.12716.28.camel@linda

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: olly@lfix.co.uk
  Subject: Re: PL/Python: How do I use result methods?
  In-Reply-To: <1097937269.12716.28.camel@linda>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox