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

Knut Anders Hatlen commented on DERBY-4371:
-------------------------------------------

The error for "select distinct i from t order by j" is raised by 
OrderByColumn.bindOrderByColumn() if the query is distinct, the sort key is a 
column reference, and the sort key has been added to the result column list. 
Ideally, we should raise the error if the query is distinct and the sort key 
has been added to the RCL, and not care about whether or not it's a column 
reference. However, we always add the sort key to the RCL if it's an 
expression, even if the same expression is already in the RCL. DERBY-4406 is 
caused by this, and a fix for that issue is likely to make it easier to fix 
this issue.

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