BUG #4733: Feature request: add plpy.query_plan(...) to plpythonu

From: "Daniel Miller" <daniel(at)keystonewood(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4733: Feature request: add plpy.query_plan(...) to plpythonu
Date: 2009-03-25 16:37:23
Message-ID: 200903251637.n2PGbNbK031256@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4733
Logged by: Daniel Miller
Email address: daniel(at)keystonewood(dot)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

Browse pgsql-bugs by date

  From Date Subject
Next Message Wayne Conrad 2009-03-25 17:54:50 Re: BUG #4730: Vacuum full verbose analyze "deadlock"
Previous Message Tom Lane 2009-03-25 15:28:44 Re: BUG #4730: Vacuum full verbose analyze "deadlock"