Skip to content

Commit f7c7f67

Browse files
committed
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.
1 parent 58d9acc commit f7c7f67

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/pl/plpgsql/src/expected/plpgsql_call.out

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ BEGIN
1717
RETURN 5;
1818
END;
1919
$$;
20-
CALL test_proc2();
21-
ERROR: cannot return a value from a procedure
22-
CONTEXT: PL/pgSQL function test_proc2() while casting return value to function's return type
20+
ERROR: RETURN cannot have a parameter in a procedure
21+
LINE 5: RETURN 5;
22+
^
2323
CREATE TABLE test1 (a int);
2424
CREATE PROCEDURE test_proc3(x int)
2525
LANGUAGE plpgsql
@@ -54,7 +54,6 @@ SELECT * FROM test1;
5454
(2 rows)
5555

5656
DROP PROCEDURE test_proc1;
57-
DROP PROCEDURE test_proc2;
5857
DROP PROCEDURE test_proc3;
5958
DROP PROCEDURE test_proc4;
6059
DROP TABLE test1;

src/pl/plpgsql/src/pl_exec.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,6 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
617617
}
618618
else if (!estate.retisnull)
619619
{
620-
if (func->fn_prokind == PROKIND_PROCEDURE)
621-
ereport(ERROR,
622-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
623-
errmsg("cannot return a value from a procedure")));
624-
625620
/*
626621
* Cast result value to function's declared result type, and copy it
627622
* out to the upper executor memory context. We must treat tuple

src/pl/plpgsql/src/pl_gram.y

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,14 +3138,21 @@ make_return_stmt(int location)
31383138
parser_errposition(yylloc)));
31393139
new->retvarno = plpgsql_curr_compile->out_param_varno;
31403140
}
3141-
else if (plpgsql_curr_compile->fn_rettype == VOIDOID &&
3142-
plpgsql_curr_compile->fn_prokind != PROKIND_PROCEDURE)
3141+
else if (plpgsql_curr_compile->fn_rettype == VOIDOID)
31433142
{
31443143
if (yylex() != ';')
3145-
ereport(ERROR,
3146-
(errcode(ERRCODE_DATATYPE_MISMATCH),
3147-
errmsg("RETURN cannot have a parameter in function returning void"),
3148-
parser_errposition(yylloc)));
3144+
{
3145+
if (plpgsql_curr_compile->fn_prokind == PROKIND_PROCEDURE)
3146+
ereport(ERROR,
3147+
(errcode(ERRCODE_SYNTAX_ERROR),
3148+
errmsg("RETURN cannot have a parameter in a procedure"),
3149+
parser_errposition(yylloc)));
3150+
else
3151+
ereport(ERROR,
3152+
(errcode(ERRCODE_DATATYPE_MISMATCH),
3153+
errmsg("RETURN cannot have a parameter in function returning void"),
3154+
parser_errposition(yylloc)));
3155+
}
31493156
}
31503157
else
31513158
{

src/pl/plpgsql/src/sql/plpgsql_call.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ BEGIN
2222
END;
2323
$$;
2424

25-
CALL test_proc2();
26-
2725

2826
CREATE TABLE test1 (a int);
2927

@@ -58,7 +56,6 @@ SELECT * FROM test1;
5856

5957

6058
DROP PROCEDURE test_proc1;
61-
DROP PROCEDURE test_proc2;
6259
DROP PROCEDURE test_proc3;
6360
DROP PROCEDURE test_proc4;
6461

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy