Skip to content

Invalid aggregate SQL query with HAVING can be executed without error (SQLancer-TLP) #12013

@2010YOUY01

Description

@2010YOUY01

Describe the bug

The following 2 queries can not be executed in DuckDB/Postgres, but can be executed without error in DataFusion.

See reproducer in datafusion-cli

DataFusion CLI v41.0.0
> create table t1(v1 int);
0 row(s) fetched.
Elapsed 0.069 seconds.

> insert into t1 values (1),(2),(3);
+-------+
| count |
+-------+
| 3     |
+-------+
1 row(s) fetched.
Elapsed 0.049 seconds.

> select * from t1 having max(v1)=3;
+------------+
| max(t1.v1) |
+------------+
| 3          |
+------------+
1 row(s) fetched.
Elapsed 0.037 seconds.

> select * from t1 having max(v1)=1;
+------------+
| max(t1.v1) |
+------------+
+------------+
0 row(s) fetched.
Elapsed 0.006 seconds.

Looks like * is expanded to the aggregate function expression i.e. max(v1) inside HAVING clause.
I think such semantics is not meaningful so report it as a potential bug.

To Reproduce

No response

Expected behavior

No response

Additional context

Found by SQLancer #11030

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions