From 98f518e1df7b75905d76ea5d048952953b3fc742 Mon Sep 17 00:00:00 2001 From: Kushaal Shroff <51415286+KushaalShroff@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:38:29 +0530 Subject: [PATCH] Fix error handling for already created functions that could give syntax error in newer releases (#3249) Our code assumes that function once created will never give syntax error. But certain fixes like 5251e4a where we disallow declaring reserved @@var, functions could have been created in earlier releases which will give syntax error while executing on a version with this commit. While throwing this syntax error at time of execution of function we have not cleaned up the contexts and aborted well which leads to a crash while executing a subsequent query. To fix this we call terminate_batch for compile errors when we get parser syntax error. In this PR We were crashing due to this in this action and by adding this commit we are not crashing anymore. Issues Resolved BABEL-5455 Signed-off-by: Kushaal Shroff --- contrib/babelfishpg_tsql/src/pl_handler.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index 6881c6a99f7..3c6729f0143 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -5349,7 +5349,7 @@ Datum pltsql_call_handler(PG_FUNCTION_ARGS) { bool nonatomic; - PLtsql_function *func; + PLtsql_function *func = NULL; PLtsql_execstate *save_cur_estate; Datum retval; int rc; @@ -5470,6 +5470,11 @@ pltsql_call_handler(PG_FUNCTION_ARGS) PG_FINALLY(); { sql_dialect = saved_dialect; + + /* If func is NULL then we have encountered a parser error. */ + if (!func) + terminate_batch(true /* send_error */ , true /* compile_error */ , current_spi_stack_depth); + } PG_END_TRY();