[
https://issues.apache.org/jira/browse/CALCITE-7536?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18081934#comment-18081934
]
Julian Hyde commented on CALCITE-7536:
--------------------------------------
1. Do you believe that that query complies with the SQL standard?
2. I presume that {{MAX(t2.col1)}} needs to be paired with an enclosing query;
if so, how is that enclosing query chosen?
3. Could {{MAX(t2.col1)}} have been used in a {{SELECT}} or {{GROUP BY}}
clause, or would that have triggered Calcite's rule (inherited from Oracle and
shared with several other database) that if a query contains an aggregate
function it automatically becomes an aggregate query?
> Validator rejects legal queries with aggregates in WHERE clauses
> ----------------------------------------------------------------
>
> Key: CALCITE-7536
> URL: https://issues.apache.org/jira/browse/CALCITE-7536
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.41.0
> Reporter: Mihai Budiu
> Priority: Minor
>
> The validator syntactically rejects queries that contain aggregates in WHERE,
> even though such aggregates may depend on outer queries and could be
> evaluated. For example, Postgres accepts the following query:
> {code}
> SELECT col1
> FROM (VALUES (1)) t1(col1)
> GROUP BY col1
> HAVING (
> SELECT MAX(t2.col1) != 0
> FROM (VALUES (1)) t2(col1)
> WHERE t2.col1 = t1.col1
> GROUP BY t2.col1
> HAVING (
> SELECT t3.col1 != 0
> FROM (VALUES (1)) t3(col1)
> WHERE t3.col1 = MAX(t2.col1)
> )
> )
> {code}
> Calcite will reject it with:
> {code}
> Aggregate expression is illegal in WHERE clause
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)