Commit f7c7f67f authored by Peter Eisentraut's avatar Peter Eisentraut

PL/pgSQL: Simplify RETURN checking for procedures

Check at compile time that RETURN in a procedure does not specify a
parameter, rather than at run time.
parent 58d9acc1
...@@ -17,9 +17,9 @@ BEGIN ...@@ -17,9 +17,9 @@ BEGIN
RETURN 5; RETURN 5;
END; END;
$$; $$;
CALL test_proc2(); ERROR: RETURN cannot have a parameter in a procedure
ERROR: cannot return a value from a procedure LINE 5: RETURN 5;
CONTEXT: PL/pgSQL function test_proc2() while casting return value to function's return type ^
CREATE TABLE test1 (a int); CREATE TABLE test1 (a int);
CREATE PROCEDURE test_proc3(x int) CREATE PROCEDURE test_proc3(x int)
LANGUAGE plpgsql LANGUAGE plpgsql
...@@ -54,7 +54,6 @@ SELECT * FROM test1; ...@@ -54,7 +54,6 @@ SELECT * FROM test1;
(2 rows) (2 rows)
DROP PROCEDURE test_proc1; DROP PROCEDURE test_proc1;
DROP PROCEDURE test_proc2;
DROP PROCEDURE test_proc3; DROP PROCEDURE test_proc3;
DROP PROCEDURE test_proc4; DROP PROCEDURE test_proc4;
DROP TABLE test1; DROP TABLE test1;
...@@ -617,11 +617,6 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo, ...@@ -617,11 +617,6 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
} }
else if (!estate.retisnull) else if (!estate.retisnull)
{ {
if (func->fn_prokind == PROKIND_PROCEDURE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot return a value from a procedure")));
/* /*
* Cast result value to function's declared result type, and copy it * Cast result value to function's declared result type, and copy it
* out to the upper executor memory context. We must treat tuple * out to the upper executor memory context. We must treat tuple
......
...@@ -3138,14 +3138,21 @@ make_return_stmt(int location) ...@@ -3138,14 +3138,21 @@ make_return_stmt(int location)
parser_errposition(yylloc))); parser_errposition(yylloc)));
new->retvarno = plpgsql_curr_compile->out_param_varno; new->retvarno = plpgsql_curr_compile->out_param_varno;
} }
else if (plpgsql_curr_compile->fn_rettype == VOIDOID && else if (plpgsql_curr_compile->fn_rettype == VOIDOID)
plpgsql_curr_compile->fn_prokind != PROKIND_PROCEDURE)
{ {
if (yylex() != ';') if (yylex() != ';')
ereport(ERROR, {
(errcode(ERRCODE_DATATYPE_MISMATCH), if (plpgsql_curr_compile->fn_prokind == PROKIND_PROCEDURE)
errmsg("RETURN cannot have a parameter in function returning void"), ereport(ERROR,
parser_errposition(yylloc))); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("RETURN cannot have a parameter in a procedure"),
parser_errposition(yylloc)));
else
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("RETURN cannot have a parameter in function returning void"),
parser_errposition(yylloc)));
}
} }
else else
{ {
......
...@@ -22,8 +22,6 @@ BEGIN ...@@ -22,8 +22,6 @@ BEGIN
END; END;
$$; $$;
CALL test_proc2();
CREATE TABLE test1 (a int); CREATE TABLE test1 (a int);
...@@ -58,7 +56,6 @@ SELECT * FROM test1; ...@@ -58,7 +56,6 @@ SELECT * FROM test1;
DROP PROCEDURE test_proc1; DROP PROCEDURE test_proc1;
DROP PROCEDURE test_proc2;
DROP PROCEDURE test_proc3; DROP PROCEDURE test_proc3;
DROP PROCEDURE test_proc4; DROP PROCEDURE test_proc4;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment