From d653454b9b70c3c5280ca014bbff5a9a180ecda4 Mon Sep 17 00:00:00 2001 From: youngjinj Date: Tue, 23 Apr 2024 19:50:30 +0900 Subject: [PATCH] For UPDATE JOIN statements, aggregate functions or analytic functions cannot be used in the SET and WHERE clauses. --- src/parser/semantic_check.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/parser/semantic_check.c b/src/parser/semantic_check.c index 464adb1392f..77fb2b049d7 100644 --- a/src/parser/semantic_check.c +++ b/src/parser/semantic_check.c @@ -4378,13 +4378,15 @@ pt_find_aggregate_analytic_post (PARSER_CONTEXT * parser, PT_NODE * tree, void * * [Note] * This function will search whether an aggregate or analytic function exists * in WHERE clause of below statements: - * INSERT, DO, SET, DELETE, SELECT, UNION, DIFFERENCE, INTERSECTION, and + * INSERT, UPDATE, DO, SET, DELETE, SELECT, UNION, DIFFERENCE, INTERSECTION, and * MERGE. * It stops searching when meets the first aggregate or analytic function. * * 1) For below node types, searching is limited to child node who containing + * SET clause: + * PT_UPDATE * WHERE clause: - * PT_DO, PT_DELETE, PT_SET_SESSION_VARIABLES, PT_SELECT + * PT_DO, PT_DELETE, PT_SET_SESSION_VARIABLES, PT_SELECT, PT_UPDATE * * 2) For below node types, searching is executed on its args: * PT_UNION, PT_DIFFERENCE, PT_INTERSECTION @@ -4450,6 +4452,24 @@ pt_find_aggregate_analytic_in_where (PARSER_CONTEXT * parser, PT_NODE * node) &find); break; + case PT_UPDATE: + /* For UPDATE JOIN statements, aggregate functions or analytic functions cannot be used + * in the SET and WHERE clauses. Aggregate functions cannot be used in the UPDATE statement, + * even if it is not an UPDATE JOIN statement. Whether aggregate functions are used is checked + * in the pt_semantic_check_local function. + */ + if (node->info.update.spec->next != NULL) + { + find = pt_find_aggregate_analytic_in_where (parser, node->info.update.assignment); + if (find != NULL) + { + break; + } + + find = pt_find_aggregate_analytic_in_where (parser, node->info.update.search_cond); + } + break; + default: /* for the rest node types, no need to search */ break;