How to get the result of a query executed by plpy

3.9k views Asked by At

I am working with postgres 9.3 and Python 2.7.

In a plpython function, I want to execute a query that returns a boolean. How can I get the boolean result?

For example:

result = plpy.execute('select 1<2 ')
2

There are 2 answers

0
Andromida On BEST ANSWER

I figured out how to do this:

query="select 1<2 as val;"
result=plpy.execute(query)
if result[0]["val"]: 
   print 'of corse: 1 < 2'
else:
   print 'this will never be printed'
3
yieldsfalsehood On

In your example result should be a list of rows. It's in the documentation here