Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25316] For UPDATE JOIN statements, aggregate functions or analytic functions cannot be used in the SET and WHERE clauses #5143

Merged
merged 7 commits into from
Jun 18, 2024
24 changes: 22 additions & 2 deletions src/parser/semantic_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -4380,13 +4380,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
Expand Down Expand Up @@ -4452,6 +4454,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;
Expand Down