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
RETURN 5;
END;
$$;
CALL test_proc2();
ERROR: cannot return a value from a procedure
CONTEXT: PL/pgSQL function test_proc2() while casting return value to function's return type
ERROR: RETURN cannot have a parameter in a procedure
LINE 5: RETURN 5;
^
CREATE TABLE test1 (a int);
CREATE PROCEDURE test_proc3(x int)
LANGUAGE plpgsql
......@@ -54,7 +54,6 @@ SELECT * FROM test1;
(2 rows)
DROP PROCEDURE test_proc1;
DROP PROCEDURE test_proc2;
DROP PROCEDURE test_proc3;
DROP PROCEDURE test_proc4;
DROP TABLE test1;
......@@ -617,11 +617,6 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
}
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
* out to the upper executor memory context. We must treat tuple
......
......@@ -3138,15 +3138,22 @@ make_return_stmt(int location)
parser_errposition(yylloc)));
new->retvarno = plpgsql_curr_compile->out_param_varno;
}
else if (plpgsql_curr_compile->fn_rettype == VOIDOID &&
plpgsql_curr_compile->fn_prokind != PROKIND_PROCEDURE)
else if (plpgsql_curr_compile->fn_rettype == VOIDOID)
{
if (yylex() != ';')
{
if (plpgsql_curr_compile->fn_prokind == PROKIND_PROCEDURE)
ereport(ERROR,
(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
{
/*
......
......@@ -22,8 +22,6 @@ BEGIN
END;
$$;
CALL test_proc2();
CREATE TABLE test1 (a int);
......@@ -58,7 +56,6 @@ SELECT * FROM test1;
DROP PROCEDURE test_proc1;
DROP PROCEDURE test_proc2;
DROP PROCEDURE test_proc3;
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