mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 00:03:57 -04:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									bbbe825f5f
								
							
						
					
					
						commit
						f2321a3f37
					
				| @ -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> | ||||
|  | ||||
| @ -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; | ||||
| } | ||||
|  | ||||
| @ -2245,7 +2245,7 @@ select refcursor_test1('test1'); | ||||
|  test1 | ||||
| (1 row) | ||||
| 
 | ||||
| fetch next from test1; | ||||
| fetch next in test1; | ||||
|  a  | ||||
| --- | ||||
|  5 | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user