ClickHouse / ClickHouse/ClickHouse

With analyzer on restriction joined_subquery_requires_alias is not working

Open
#68,202 1 comment 0 reactions 0 assignees View on GitHub
bug comp-query-analyzer external
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

Version 24.7

```sql
SELECT * FROM (
SELECT * FROM
(
SELECT number AS a
FROM numbers(6,10)
) as t
PASTE JOIN
(
SELECT number AS a
FROM numbers(5)
ORDER BY a DESC
)
)
FORMAT Pretty;
```
```
+----+----+
| a | a |
+----+----+
1. | 6 | 6 |
+----+----+
2. | 7 | 7 |
+----+----+
3. | 8 | 8 |
+----+----+
4. | 9 | 9 |
+----+----+
5. | 10 | 10 |
+----+----+
```

When analyzer is off I get an expected exception:
```
Received exception from server (version 24.7.3):
Code: 206. DB::Exception: Received from localhost:9000. DB::Exception: No alias for subquery or table function in JOIN (set joined_subquery_requires_alias=0 to disable restriction). While processing ' (SELECT number AS a FROM numbers(5) ORDER BY a DESC)'. (ALIAS_REQUIRED)
```

If I add `as t2` to second SELECT in JOIN I will get the correct result:
```sql
SELECT * FROM (
SELECT * FROM
(
SELECT number AS a
FROM numbers(6,10)
) as t
PASTE JOIN
(
SELECT number AS a
FROM numbers(5)
ORDER BY a DESC
) as t2
)
FORMAT Pretty;
```
```
+----+------+
| a | t2.a |
+----+------+
1. | 6 | 4 |
+----+------+
2. | 7 | 3 |
+----+------+
3. | 8 | 2 |
+----+------+
4. | 9 | 1 |
+----+------+
5. | 10 | 0 |
+----+------+
```

Also I get different result with `joined_subquery_requires_alias=0` when analyzer if on and off:
https://fiddle.clickhouse.com/e190b37f-3ad3-4761-bed4-6ec44a610bb6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.