Re: Tuning queries inside a function - Mailing list pgsql-general

From Tom Lane
Subject Re: Tuning queries inside a function
Date
Msg-id 1025.1115060708@sss.pgh.pa.us
Whole thread Raw
In response to Re: Tuning queries inside a function  ("Joshua D. Drake" <jd@commandprompt.com>)
List pgsql-general
"Joshua D. Drake" <jd@commandprompt.com> writes:
> Mike Nolan wrote:
>> That part I get, but I cannot seem to get an 'explain select....' to return
>> the explain output inside a function.

> Oh interesting. Hmmm. Alvaro can you think of a way to execute the
> result into a variable and return it as a notice?

I think it's done already, at least if you are using a recent release.
I note the following relevant items in the CVS log:

2005-04-05 14:05  tgl

    * doc/src/sgml/plpgsql.sgml, src/pl/plpgsql/src/gram.y: Adjust
    grammar for plpgsql's OPEN command so that a cursor can be OPENed
    on non-SELECT commands such as EXPLAIN or SHOW (anything that
    returns tuples is allowed).  This flexibility already existed for
    bound cursors, but OPEN was artificially restricting what it would
    take.  Per a gripe some months back.

2005-02-10 15:36  tgl

    * src/backend/: executor/spi.c, tcop/pquery.c (REL8_0_STABLE),
    executor/spi.c, tcop/pquery.c: Fix SPI cursor support to allow
    scanning the results of utility commands that return tuples (such
    as EXPLAIN).  Per gripe from Michael Fuhr.  Side effect: fix an old
    bug that unintentionally disabled backward scans for all
    SPI-created cursors.

(The latter is in 8.0.2 and up, the former only in CVS tip.)

This is relevant to plpgsql because both "FOR ... IN query" and plpgsql
cursors depend on SPI cursors.

            regards, tom lane

pgsql-general by date:

Previous
From: Vlad
Date:
Subject: Re: [Dbdpg-general] Re: 'prepare' is not quite schema-safe
Next
From: Jonel Rienton
Date:
Subject: PostgreSQL 8.0.2 and Tiger