[ 
https://issues.apache.org/jira/browse/DERBY-2374?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770400#action_12770400
 ] 

Mamta A. Satoor commented on DERBY-2374:
----------------------------------------

I am looking at this more, but the root of the problem might be the following 
piece of code in sqlgrammar.jj in FromTable tableFactor() throws 
StandardException method

|
        // There is a grammar ambiguity with nested parentheses here.
        // A series of left parentheses could introduce either a table
        // reference or a derived table.  For example:
        //
        //              (((select c from t) a inner join (select d from s) b ))
        //
        // and:
        //
        //              (((select c from t) a)))
        //
        // To distinguish these two cases, we consider anything that starts
        // with a single parenthesis and either SELECT or VALUES to be
        // a derived table, and anything else to be a table reference.
        // Note that we can't use the subqueryFollows() lookahead method,
        // because it skips over all leading left parentheses to decide
        // whether a subquery follows.
        LOOKAHEAD( {
                                getToken(1).kind == LEFT_PAREN &&
                                (
                                        getToken(2).kind == SELECT ||
                                        getToken(2).kind == VALUES
                                )
                        } )

I will debug more but it looks like we are not differentiating correctly the 
first select inside the parenthese to mean <left paren> <query expression body> 
<right paren>
select c1 from ((select t1.c1 from t1) union (select t2.c1 from t2)) t1t2;


> UNION PROBLEM WITH PARENTHESIS
> ------------------------------
>
>                 Key: DERBY-2374
>                 URL: https://issues.apache.org/jira/browse/DERBY-2374
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.1.3.3, 10.2.2.0, 10.3.3.1, 10.4.2.1, 10.5.3.1, 
> 10.6.0.0
>            Reporter: Kenneth Gee
>            Priority: Minor
>
> The following query shows the error using the Derby demo toursDB:
> SELECT FLIGHT_ID , SEGMENT_NUMBER , ARRIVE_TIME
>   FROM (
>          (SELECT HW.FLIGHT_ID , HW.SEGMENT_NUMBER , HW.ARRIVE_TIME FROM 
> FLIGHTS HW)
>            UNION
>          (SELECT SW.FLIGHT_ID , SW.SEGMENT_NUMBER , SW.ARRIVE_TIME FROM 
> FLIGHTS SW)
>        ) SRC;
> ERROR 42X01: Syntax error: Encountered "UNION" at line 4, column 12.
> The following query works:
> SELECT FLIGHT_ID , SEGMENT_NUMBER , ARRIVE_TIME
>   FROM (
>          SELECT HW.FLIGHT_ID , HW.SEGMENT_NUMBER , HW.ARRIVE_TIME FROM 
> FLIGHTS HW
>           UNION
>          SELECT SW.FLIGHT_ID , SW.SEGMENT_NUMBER , SW.ARRIVE_TIME FROM 
> FLIGHTS SW
>        )  SRC;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to