aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2007-04-28 23:54:59 +0000
committerNeil Conway <neilc@samurai.com>2007-04-28 23:54:59 +0000
commitf2321a3f37b74b42d20ec787afb7ee4a29655a3e (patch)
tree7bd72dce472a841133f9082104c5b0f26860c492
parentbbbe825f5f46d7ead60502f43d3b414719a41aa5 (diff)
downloadpostgresql-f2321a3f37b74b42d20ec787afb7ee4a29655a3e.tar.gz
postgresql-f2321a3f37b74b42d20ec787afb7ee4a29655a3e.zip
Add support for IN as alternative to FROM in PL/PgSQL's FETCH statement,
for consistency with the backend's FETCH command. Patch from Pavel Stehule, reviewed by Neil Conway.
-rw-r--r--doc/src/sgml/plpgsql.sgml4
-rw-r--r--src/pl/plpgsql/src/gram.y25
-rw-r--r--src/test/regress/expected/plpgsql.out2
-rw-r--r--src/test/regress/sql/plpgsql.sql2
4 files changed, 23 insertions, 10 deletions
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml
index abfc8b6ec64..97090b7316d 100644
--- a/doc/src/sgml/plpgsql.sgml
+++ b/doc/src/sgml/plpgsql.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.107 2007/04/16 17:21:22 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.108 2007/04/28 23:54:58 neilc Exp $ -->
<chapter id="plpgsql">
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -2523,7 +2523,7 @@ OPEN curs3(42);
<title><literal>FETCH</></title>
<synopsis>
-FETCH <optional> <replaceable>direction</replaceable> FROM </optional> <replaceable>cursor</replaceable> INTO <replaceable>target</replaceable>;
+FETCH <optional> <replaceable>direction</replaceable> { FROM | IN } </optional> <replaceable>cursor</replaceable> INTO <replaceable>target</replaceable>;
</synopsis>
<para>
diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y
index c04f5a9b4d7..48c2ed67852 100644
--- a/src/pl/plpgsql/src/gram.y
+++ b/src/pl/plpgsql/src/gram.y
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.100 2007/04/16 17:21:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.101 2007/04/28 23:54:59 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2043,13 +2043,15 @@ read_fetch_direction(void)
else if (pg_strcasecmp(yytext, "absolute") == 0)
{
fetch->direction = FETCH_ABSOLUTE;
- fetch->expr = plpgsql_read_expression(K_FROM, "FROM");
+ fetch->expr = read_sql_construct(K_FROM, K_IN, "FROM or IN",
+ "SELECT ", true, true, NULL);
check_FROM = false;
}
else if (pg_strcasecmp(yytext, "relative") == 0)
{
fetch->direction = FETCH_RELATIVE;
- fetch->expr = plpgsql_read_expression(K_FROM, "FROM");
+ fetch->expr = read_sql_construct(K_FROM, K_IN, "FROM or IN",
+ "SELECT ", true, true, NULL);
check_FROM = false;
}
else if (pg_strcasecmp(yytext, "forward") == 0)
@@ -2060,6 +2062,13 @@ read_fetch_direction(void)
{
fetch->direction = FETCH_BACKWARD;
}
+ else if (tok != T_SCALAR)
+ {
+ plpgsql_push_back_token(tok);
+ fetch->expr = read_sql_construct(K_FROM, K_IN, "FROM or IN",
+ "SELECT ", true, true, NULL);
+ check_FROM = false;
+ }
else
{
/* Assume there's no direction clause */
@@ -2067,9 +2076,13 @@ read_fetch_direction(void)
check_FROM = false;
}
- /* check FROM keyword after direction's specification */
- if (check_FROM && yylex() != K_FROM)
- yyerror("expected \"FROM\"");
+ /* check FROM or IN keyword after direction's specification */
+ if (check_FROM)
+ {
+ tok = yylex();
+ if (tok != K_FROM && tok != K_IN)
+ yyerror("expected FROM or IN");
+ }
return fetch;
}
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index 02ef15c6770..669077edee7 100644
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -2245,7 +2245,7 @@ select refcursor_test1('test1');
test1
(1 row)
-fetch next from test1;
+fetch next in test1;
a
---
5
diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql
index 1cc9df2de2d..33637d9e798 100644
--- a/src/test/regress/sql/plpgsql.sql
+++ b/src/test/regress/sql/plpgsql.sql
@@ -1918,7 +1918,7 @@ $$ language plpgsql;
begin;
select refcursor_test1('test1');
-fetch next from test1;
+fetch next in test1;
select refcursor_test1('test2');
fetch all from test2;