diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-08-12 20:05:56 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-08-12 20:05:56 +0000 |
commit | 3f8db37c2f1eeeffd9dae3189b783a463f56fe77 (patch) | |
tree | f6520123161af6191b5f53262d67eab69b24eccf /src/backend/parser | |
parent | 883f4b42d7292f1a7142e55046cee86f92049b5a (diff) | |
download | postgresql-3f8db37c2f1eeeffd9dae3189b783a463f56fe77.tar.gz |
Tweak SPI_cursor_open to allow INSERT/UPDATE/DELETE RETURNING; this was
merely a matter of fixing the error check, since the underlying Portal
infrastructure already handles it. This in turn allows these statements
to be used in some existing plpgsql and plperl contexts, such as a
plpgsql FOR loop. Also, do some marginal code cleanup in places that
were being sloppy about distinguishing SELECT from SELECT INTO.
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/analyze.c | 11 | ||||
-rw-r--r-- | src/backend/parser/parse_clause.c | 4 | ||||
-rw-r--r-- | src/backend/parser/parse_expr.c | 4 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 61242ef712..39c7372733 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.345 2006/08/12 02:52:05 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.346 2006/08/12 20:05:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -3116,6 +3116,15 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt) /* Shouldn't get any extras, since grammar only allows SelectStmt */ if (extras_before || extras_after) elog(ERROR, "unexpected extra stuff in cursor statement"); + if (!IsA(stmt->query, Query) || + ((Query *) stmt->query)->commandType != CMD_SELECT) + elog(ERROR, "unexpected non-SELECT command in cursor statement"); + + /* But we must explicitly disallow DECLARE CURSOR ... SELECT INTO */ + if (((Query *) stmt->query)->into) + ereport(ERROR, + (errcode(ERRCODE_INVALID_CURSOR_DEFINITION), + errmsg("DECLARE CURSOR may not specify INTO"))); return result; } diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index d34529c74e..021fb3fa55 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.155 2006/07/26 19:31:51 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.156 2006/08/12 20:05:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -447,7 +447,7 @@ transformRangeSubselect(ParseState *pstate, RangeSubselect *r) if (query->commandType != CMD_SELECT) elog(ERROR, "expected SELECT query from subquery in FROM"); - if (query->resultRelation != 0 || query->into != NULL) + if (query->into != NULL) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("subquery in FROM may not have SELECT INTO"))); diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 6a7117e98b..0812c3d441 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.196 2006/08/02 01:59:46 joe Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.197 2006/08/12 20:05:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1104,7 +1104,7 @@ transformSubLink(ParseState *pstate, SubLink *sublink) elog(ERROR, "bad query in sub-select"); qtree = (Query *) linitial(qtrees); if (qtree->commandType != CMD_SELECT || - qtree->resultRelation != 0) + qtree->into != NULL) elog(ERROR, "bad query in sub-select"); sublink->subselect = (Node *) qtree; |