duerwuyi opened a new issue, #37431:
URL: https://github.com/apache/shardingsphere/issues/37431
## Bug Report
### Which version of ShardingSphere did you use?
shardingsphere-proxy 5.5.2
postgres 17.2 as backend
### Expected behavior
The query should execute successfully (same as PostgreSQL behavior), because
the subquery is correlated and should be able to reference outer query columns
in WHERE.
### Actual behavior
The following query fails with:
ERROR: Unknown column 'ref_0.c13' in 'where clause'
```sql
testdb=> SET DEFAULT SINGLE TABLE STORAGE UNIT = ds_0;
SUCCESS
testdb=> DROP TABLE IF EXISTS t3;
DROP TABLE
testdb=> DROP TABLE IF EXISTS t2;
DROP TABLE
testdb=> CREATE TABLE t3 (c13 INT);
CREATE TABLE
testdb=> CREATE TABLE t2 (vkey INT, c8 TEXT);
CREATE TABLE
---sql
testdb=> select
ref_0.c13 as c_0
from
t3 as ref_0
group by ref_0.c13
having 'a' = (
select ref_2.c8 as c_0
from t2 as ref_2
where (ref_0.c13) between (ref_2.vkey) and (ref_2.vkey)
limit 1
);
ERROR: Unknown column 'ref_0.c13' in 'where clause'.
```
If I comment out the WHERE clause in the subquery (remove the correlated
reference), the query runs successfully.
We consider that the tables are all single tables stored in the same storage
unit, so it may not be a problem of federation engine (We did not enable it).
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
[ss_postgres.zip](https://github.com/user-attachments/files/24228864/ss_postgres.zip)
run `docker compose up -d` in this file.
SQL to execute are shown above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]