Skip to content

Commit f2321a3

Browse files
author
Neil Conway
committed
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.
1 parent bbbe825 commit f2321a3

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

doc/src/sgml/plpgsql.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.107 2007/04/16 17:21:22 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.108 2007/04/28 23:54:58 neilc Exp $ -->
22

33
<chapter id="plpgsql">
44
<title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -2523,7 +2523,7 @@ OPEN curs3(42);
25232523
<title><literal>FETCH</></title>
25242524

25252525
<synopsis>
2526-
FETCH <optional> <replaceable>direction</replaceable> FROM </optional> <replaceable>cursor</replaceable> INTO <replaceable>target</replaceable>;
2526+
FETCH <optional> <replaceable>direction</replaceable> { FROM | IN } </optional> <replaceable>cursor</replaceable> INTO <replaceable>target</replaceable>;
25272527
</synopsis>
25282528

25292529
<para>

src/pl/plpgsql/src/gram.y

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.100 2007/04/16 17:21:23 tgl Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.101 2007/04/28 23:54:59 neilc Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -2043,13 +2043,15 @@ read_fetch_direction(void)
20432043
else if (pg_strcasecmp(yytext, "absolute") == 0)
20442044
{
20452045
fetch->direction = FETCH_ABSOLUTE;
2046-
fetch->expr = plpgsql_read_expression(K_FROM, "FROM");
2046+
fetch->expr = read_sql_construct(K_FROM, K_IN, "FROM or IN",
2047+
"SELECT ", true, true, NULL);
20472048
check_FROM = false;
20482049
}
20492050
else if (pg_strcasecmp(yytext, "relative") == 0)
20502051
{
20512052
fetch->direction = FETCH_RELATIVE;
2052-
fetch->expr = plpgsql_read_expression(K_FROM, "FROM");
2053+
fetch->expr = read_sql_construct(K_FROM, K_IN, "FROM or IN",
2054+
"SELECT ", true, true, NULL);
20532055
check_FROM = false;
20542056
}
20552057
else if (pg_strcasecmp(yytext, "forward") == 0)
@@ -2060,16 +2062,27 @@ read_fetch_direction(void)
20602062
{
20612063
fetch->direction = FETCH_BACKWARD;
20622064
}
2065+
else if (tok != T_SCALAR)
2066+
{
2067+
plpgsql_push_back_token(tok);
2068+
fetch->expr = read_sql_construct(K_FROM, K_IN, "FROM or IN",
2069+
"SELECT ", true, true, NULL);
2070+
check_FROM = false;
2071+
}
20632072
else
20642073
{
20652074
/* Assume there's no direction clause */
20662075
plpgsql_push_back_token(tok);
20672076
check_FROM = false;
20682077
}
20692078

2070-
/* check FROM keyword after direction's specification */
2071-
if (check_FROM && yylex() != K_FROM)
2072-
yyerror("expected \"FROM\"");
2079+
/* check FROM or IN keyword after direction's specification */
2080+
if (check_FROM)
2081+
{
2082+
tok = yylex();
2083+
if (tok != K_FROM && tok != K_IN)
2084+
yyerror("expected FROM or IN");
2085+
}
20732086

20742087
return fetch;
20752088
}

src/test/regress/expected/plpgsql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ select refcursor_test1('test1');
22452245
test1
22462246
(1 row)
22472247

2248-
fetch next from test1;
2248+
fetch next in test1;
22492249
a
22502250
---
22512251
5

src/test/regress/sql/plpgsql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ $$ language plpgsql;
19181918
begin;
19191919

19201920
select refcursor_test1('test1');
1921-
fetch next from test1;
1921+
fetch next in test1;
19221922

19231923
select refcursor_test1('test2');
19241924
fetch all from test2;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy