Re: Prepare/Declare - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Prepare/Declare
Date
Msg-id 20209.1180037247@sss.pgh.pa.us
Whole thread Raw
In response to Prepare/Declare  (Michael Meskes <meskes@postgresql.org>)
Responses Re: Prepare/Declare  (Michael Meskes <meskes@postgresql.org>)
List pgsql-hackers
Michael Meskes <meskes@postgresql.org> writes:
> PREPARE p AS
>     SELECT * FROM foo;
> DECLARE c CURSOR for p;

> AFAIRC the standard says this group of statements are perfectly legal

I'd be interested to see where you draw that conclusion, since
(a) PREPARE statements of that form are not in the standard, and
(b) DECLARE CURSOR is clearly defined as taking a <query expression>.

It doesn't seem like an amazingly sensible thing to do, either.
DECLARE CURSOR affects the plan generated for its query (eg,
backwards-scrollability may be required), so it's not certain that
a previously PREPARE'd plan could be used.

You can achieve something approximating this at the protocol level,
since you can do partial fetches from a portal created by Bind'ing
the prepared statement.  That won't let you fetch backwards nor
persist the cursor past end of transaction, but maybe you don't
need those things.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Michael Meskes
Date:
Subject: Prepare/Declare
Next
From: Bernd Helmle
Date:
Subject: Reviewing temp_tablespaces GUC patch