The following bug has been logged online: Bug reference: 4733 Logged by: Daniel Miller Email address: dan...@keystonewood.com PostgreSQL version: 8.x Operating system: N/A Description: Feature request: add plpy.query_plan(...) to plpythonu Details:
I have coded a function that I find very useful in plpythonu functions. The advantage of this function is that it prepares a query plan and returns a python function that can simply be called with the necessary arguments to execute the query. Could this be added as a function like plpy.execute(...) and plpy.prepare(...) ? <function source> def query_plan(query, *argtypes, **flags): """Prepare a query plan and store it in the static data (SD) dict Arguments: query - the query to prepare *argtypes - argument type names (example: "int4", "text", "bool", etc.) returns a function that takes arguments corresponding to the given argtypes. The function also takes an optional 'limit' keyword argument. When called, the function will execute the query and return the query result object. """ if query in SD: return SD[query] plan = plpy.prepare(query, argtypes) def exec_query(*args, **kw): if "limit" in kw: limit = (kw.pop("limit"),) else: limit = () if kw: raise TypeError("unexpected keyword arguments: %s" % ", ".join(kw)) return plpy.execute(plan, list(args), *limit) SD[query] = exec_query return exec_query </function source> Thanks. ~ Daniel -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs