jonahgao opened a new issue, #10914:
URL: https://github.com/apache/datafusion/issues/10914

   ### Describe the bug
   
   In the following query:
   ```sql
   (with cte as (select 1) select * from cte) 
   union 
   (select * from cte)
   ```
   The visibility of the `cte` should be limited to the subquery on the left 
side of the UNION.
   
   ### To Reproduce
   
   Run the following queries in CLI:
   ```sh
   > create table t as values(100);
   0 row(s) fetched.
   Elapsed 0.025 seconds.
   
   > (with t as (select 1) select * from t) union (select * from t);
   +----------+
   | Int64(1) |
   +----------+
   | 1        |
   +----------+
   1 row(s) fetched.
   Elapsed 0.025 seconds.
   ```
   
   ### Expected behavior
   
   The subquery on the right should not reference the CTE, and the result 
should be the same as in PostgreSQL.
   
   ```sh
   postgres=# create table t as values(100);
   SELECT 1
   
   postgres=# (with t as (select 1) select * from t) union (select * from t);
    ?column?
   ----------
         100
           1
   (2 rows)
   ```
   
   ### Additional context
   
   _No response_


-- 
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: github-unsubscr...@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to