From: Tom Lane Date: Thu, 15 Apr 2004 13:01:45 +0000 (+0000) Subject: Improve syntax error messages for invalid-argument cases in RETURN and X-Git-Tag: REL8_0_0BETA1~823 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c72f44c623993407e7f155d5501be8f25f3df00;p=postgresql Improve syntax error messages for invalid-argument cases in RETURN and RETURN NEXT. --- diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y index c116d5fb4d..fb46e1083b 100644 --- a/src/pl/plpgsql/src/gram.y +++ b/src/pl/plpgsql/src/gram.y @@ -4,7 +4,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.52 2004/03/24 23:38:49 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.53 2004/04/15 13:01:45 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -1136,8 +1136,12 @@ stmt_return : K_RETURN lno new->retrecno = -1; new->retrowno = -1; - if (plpgsql_curr_compile->fn_retistuple && - !plpgsql_curr_compile->fn_retset) + if (plpgsql_curr_compile->fn_retset) + { + if (yylex() != ';') + yyerror("RETURN cannot have a parameter in function returning set; use RETURN NEXT"); + } + else if (plpgsql_curr_compile->fn_retistuple) { switch (yylex()) { @@ -1153,14 +1157,17 @@ stmt_return : K_RETURN lno break; default: - yyerror("return type mismatch in function returning tuple"); + yyerror("RETURN must specify a record or row variable in function returning tuple"); break; } if (yylex() != ';') - yyerror("expected \";\""); + yyerror("RETURN must specify a record or row variable in function returning tuple"); } else + { + /* ordinary expression case */ new->expr = plpgsql_read_expression(';', ";"); + } new->cmd_type = PLPGSQL_STMT_RETURN; new->lineno = $2; @@ -1173,6 +1180,9 @@ stmt_return_next: K_RETURN_NEXT lno { PLpgSQL_stmt_return_next *new; + if (!plpgsql_curr_compile->fn_retset) + yyerror("cannot use RETURN NEXT in a non-SETOF function"); + new = malloc(sizeof(PLpgSQL_stmt_return_next)); memset(new, 0, sizeof(PLpgSQL_stmt_return_next)); @@ -1188,10 +1198,10 @@ stmt_return_next: K_RETURN_NEXT lno else if (tok == T_ROW) new->row = yylval.row; else - yyerror("incorrect argument to RETURN NEXT"); + yyerror("RETURN NEXT must specify a record or row variable in function returning tuple"); if (yylex() != ';') - yyerror("expected \";\""); + yyerror("RETURN NEXT must specify a record or row variable in function returning tuple"); } else new->expr = plpgsql_read_expression(';', ";");