From 3d8874224ff25de3ca4f9da8ce3118391bd6609e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 13 Dec 2017 10:37:48 -0500 Subject: [PATCH] Fix crash when using CALL on an aggregate Author: Ashutosh Bapat Reported-by: Rushabh Lathia --- src/backend/parser/parse_func.c | 9 +++++++++ src/test/regress/expected/create_procedure.out | 9 +++++++++ src/test/regress/sql/create_procedure.sql | 3 +++ 3 files changed, 21 insertions(+) diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index 2f20516e76..e6b085637b 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -336,6 +336,15 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Form_pg_aggregate classForm; int catDirectArgs; + if (proc_call) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_FUNCTION), + errmsg("%s is not a procedure", + func_signature_string(funcname, nargs, + argnames, + actual_arg_types)), + parser_errposition(pstate, location))); + tup = SearchSysCache1(AGGFNOID, ObjectIdGetDatum(funcid)); if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "cache lookup failed for aggregate %u", funcid); diff --git a/src/test/regress/expected/create_procedure.out b/src/test/regress/expected/create_procedure.out index 5538ef2f2b..e627d8ebbc 100644 --- a/src/test/regress/expected/create_procedure.out +++ b/src/test/regress/expected/create_procedure.out @@ -41,6 +41,15 @@ SELECT 5; $$; CALL ptest2(); -- various error cases +CALL version(); -- error: not a procedure +ERROR: version() is not a procedure +LINE 1: CALL version(); + ^ +HINT: To call a function, use SELECT. +CALL sum(1); -- error: not a procedure +ERROR: sum(integer) is not a procedure +LINE 1: CALL sum(1); + ^ CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; ERROR: invalid attribute in procedure definition LINE 1: CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT I... diff --git a/src/test/regress/sql/create_procedure.sql b/src/test/regress/sql/create_procedure.sql index f09ba2ad30..8c47b7e9ef 100644 --- a/src/test/regress/sql/create_procedure.sql +++ b/src/test/regress/sql/create_procedure.sql @@ -30,6 +30,9 @@ CALL ptest2(); -- various error cases +CALL version(); -- error: not a procedure +CALL sum(1); -- error: not a procedure + CREATE PROCEDURE ptestx() LANGUAGE SQL WINDOW AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; CREATE PROCEDURE ptestx() LANGUAGE SQL STRICT AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES (1, 'a') $$; -- 2.40.0