mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
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.
This commit is contained in:
@ -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;
|
|||||||
(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,
|
|||||||
}
|
}
|
||||||
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,15 +3138,22 @@ 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() != ';')
|
||||||
|
{
|
||||||
|
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,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||||
errmsg("RETURN cannot have a parameter in function returning void"),
|
errmsg("RETURN cannot have a parameter in function returning void"),
|
||||||
parser_errposition(yylloc)));
|
parser_errposition(yylloc)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -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;
|
|||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user