With pgsql function SelRec(integer) as defined below:
-- select record
CREATE OR REPLACE FUNCTION SelRec(_sno integer)
RETURNS SETOF app_for_leave AS
$BODY$
BEGIN
RETURN QUERY
SELECT * FROM "app_for_leave" WHERE "sno"=_sno;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
I tried to call this function inside my python code, and expected the returned result as query object which furthermore I could get an individual value inside the query object.
import psycopg2
connection_string = 'postgresql://postgres:111111@localhost:5432/myDB'
conn = psycopg2.connect(connection_string)
cursor = conn.cursor()
obj = cursor.execute("select * from SelRec(1)");
conn.commit()
print obj # None
Yet, the result is None as if there is no data stored, but it does exist like below:
sno | eid | ename | sd | ed | sid | status
-----+-----+-------+------------+------------+-----+--------
1 | 101 | | 2013-04-04 | 2013-04-04 | 2 | f
My need is the obj return an query object which I would further call DataSet = obj.first(), and DataSet.status, ect for each individual value.
Any suggestion how I can achieve that? Thanks.