Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the result of a query executed by plpy

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 ')
like image 815
Andromida Avatar asked Jan 23 '26 11:01

Andromida


2 Answers

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'
like image 71
Andromida Avatar answered Jan 25 '26 09:01

Andromida


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

like image 43
yieldsfalsehood Avatar answered Jan 25 '26 11:01

yieldsfalsehood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!