Whether expression may be placed as one item of an aggregate SELECT list —
SELECT <expression> AS [Agg_0] FROM <entity view> WHERE … — for an entity whose columns are
columns, and the SQL to run for it.
Allowed: exactly one call to an aggregate function (COUNT, SUM, AVG, MIN, MAX, STDEV, VAR,
STRING_AGG, …) with nothing before or after it. Inside the call: the given columns, * for
COUNT, DISTINCT, constants, arithmetic, comparison and logical operators, CASE, CAST, and a
fixed set of pure scalar functions. Everything else is refused: statement separators, comments,
backslashes inside quoted strings or identifiers, subqueries, other tables, qualified names,
variables, aliases, window clauses, and any shape the parser produces that this check does not
read.
The caller's text is never run. AggregateExpressionCheck.SQL is rebuilt from the
checked parse tree: columns come from columns and are quoted for the dialect; function names,
type names, operators and keywords come from fixed lists; string and number constants are
re-quoted or re-checked. So the database runs exactly the expression that was checked, even
where the parser and the database would read the caller's text differently.
Whether
expressionmay be placed as one item of an aggregate SELECT list —SELECT <expression> AS [Agg_0] FROM <entity view> WHERE …— for an entity whose columns arecolumns, and the SQL to run for it.Allowed: exactly one call to an aggregate function (COUNT, SUM, AVG, MIN, MAX, STDEV, VAR, STRING_AGG, …) with nothing before or after it. Inside the call: the given columns,
*for COUNT, DISTINCT, constants, arithmetic, comparison and logical operators, CASE, CAST, and a fixed set of pure scalar functions. Everything else is refused: statement separators, comments, backslashes inside quoted strings or identifiers, subqueries, other tables, qualified names, variables, aliases, window clauses, and any shape the parser produces that this check does not read.The caller's text is never run. AggregateExpressionCheck.SQL is rebuilt from the checked parse tree: columns come from
columnsand are quoted for the dialect; function names, type names, operators and keywords come from fixed lists; string and number constants are re-quoted or re-checked. So the database runs exactly the expression that was checked, even where the parser and the database would read the caller's text differently.