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

Bryan Pendleton commented on DERBY-4371:
----------------------------------------

Hi Nirmal, thanks for looking at this issue.

I wonder if it would be helpful to take a close look at how GROUP BY handles
a somewhat similar situation:

  select a, sum(b) from t group by a having a+c > 1 

is not legal because of the reference to column 'c'. But, the related statement:

  select a+c, sum(b) from t group by a+c having a+c > 1 

is legal, because the expression is the same in all cases (I think -- please 
check this!)

You can find the code that implements this behavior, I think, in the method
addNewColumnsForAggregation() in GroupByNode.java. In particular, look
closely at how the SubstituteExpressionsVisitor and CollectNodesVisitor
get used to process the HAVING clause's expression tree.


> Non-selected columns for SELECT DISTINCT allowed in ORDER BY clause if 
> ordered by expression
> --------------------------------------------------------------------------------------------
>
>                 Key: DERBY-4371
>                 URL: https://issues.apache.org/jira/browse/DERBY-4371
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.1.1
>            Reporter: Bernt M. Johnsen
>            Assignee: C.S. Nirmal J. Fernando
>            Priority: Critical
>
> How to repeat:
> ij> create table t (i integer, j integer);;
> 0 rows inserted/updated/deleted
> ij> insert into t values (1,2),(1,3);
> 2 rows inserted/updated/deleted
> ij> select distinct i from t order by j;
> ERROR 42879: The ORDER BY clause may not contain column 'J', since the query 
> specifies DISTINCT and that column does not appear in the query result.
> ij> select distinct i from t order by j*2;
> I          
> -----------
> 1          
> 1          
> 2 rows selected

-- 
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