Thread

  1. PL/Python: How do I use result methods?

    Oliver Elphick <olly@lfix.co.uk> — 2004-10-16T14:34:29Z

    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