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

Поиск
Список
Период
Сортировка
От Daniel Miller
Тема BUG #4733: Feature request: add plpy.query_plan(...) to plpythonu
Дата
Msg-id 200903251637.n2PGbNbK031256@wwwmaster.postgresql.org
обсуждение исходный текст
Список pgsql-bugs
The following bug has been logged online:

Bug reference:      4733
Logged by:          Daniel Miller
Email address:      daniel@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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #4730: Vacuum full verbose analyze "deadlock"
Следующее
От: Wayne Conrad
Дата:
Сообщение: Re: BUG #4730: Vacuum full verbose analyze "deadlock"