-
OPEN FOR SELECT>
+
OPEN FOR query>
-OPEN unbound_cursor FOR SELECT ...;
+OPEN unbound_cursor FOR query ;
- The cursor variable is opened and given the specified query to
+ The cursor variable is opened and given the specified query to
execute. The cursor cannot be open already, and it must have been
declared as an unbound cursor (that is, as a simple
- refcursor> variable). The SELECT query
- is treated in the same way as other SELECT
- statements in
PL/pgSQL>: PL/pgSQL>
+ refcursor> variable). The query must be a
+ SELECT, or something else that returns rows
+ (such as EXPLAIN>). The query
+ is treated in the same way as other SQL commands in
variable names are substituted, and the query plan is cached for
possible reuse.
execute. The cursor cannot be open already, and it must have been
declared as an unbound cursor (that is, as a simple
refcursor> variable). The query is specified as a string
- expression in the same way as in the EXECUTE
+ expression, in the same way as in the EXECUTE
command. As usual, this gives flexibility so the query can vary
from one run to the next.
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.67 2005/04/05 06:22:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.68 2005/04/05 18:05:46 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
if ($3->cursor_explicit_expr == NULL)
{
tok = yylex();
-
if (tok != K_FOR)
{
plpgsql_error_lineno = $2;
}
tok = yylex();
- switch (tok)
+ if (tok == K_EXECUTE)
{
- case K_SELECT:
- case '(':
- plpgsql_push_back_token(tok);
- new->query = read_sql_stmt("");
- break;
-
- case K_EXECUTE:
- new->dynquery = read_sql_stmt("SELECT ");
- break;
-
- default:
- plpgsql_error_lineno = $2;
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error at \"%s\"",
- yytext)));
+ new->dynquery = read_sql_stmt("SELECT ");
+ }
+ else
+ {
+ plpgsql_push_back_token(tok);
+ new->query = read_sql_stmt("");
}
-
}
else
{
char *cp;
tok = yylex();
-
if (tok != '(')
{
plpgsql_error_lineno = plpgsql_scanner_lineno();
else
{
tok = yylex();
-
if (tok == '(')
{
plpgsql_error_lineno = plpgsql_scanner_lineno();