The Cursor.callproc method in pyPgSQL (at least up to version 1.5) has two problems. First, it takes *args instead of a single args parameter, which is contrary to the DBAPI spec and most other implementations of it. Second, it calls 'select proc(args)', which does not allow fetchall() to retrieve its return value. Therefore, this patches pyPgSQL.Cursor.callproc to take a single args param, and to execute 'select * from proc(args)', which allows fetchall() to work properly. It'd be nice if a future version of pyPgSQL used the "*" form of the call.
from pyPgSQL import PgSQL as pgsql
if not hasattr(pgsql.Cursor, "_old_callproc"):
def callproc2(self, proc, args):
Call a stored procedure with a fetchable return value.
Note that this takes a single args attribute instead
return self._old_callproc(" * from " + proc, *args)
pgsql.Cursor._old_callproc = pgsql.Cursor.callproc
pgsql.Cursor.callproc = callproc2
Log in to post a comment.