You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "C.S. Nirmal J. Fernando (JIRA)" <ji...@apache.org> on 2010/04/19 16:10:50 UTC

[jira] Commented: (DERBY-4371) Non-selected columns for SELECT DISTINCT allowed in ORDER BY clause if ordered by expression

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

C.S. Nirmal J. Fernando commented on DERBY-4371:
------------------------------------------------

Hi All,

I like to do some work on this bug as well. If someone can suggest me a starting point, it would be great.

Following is some of my understandings/ findings, please correct me if I am wrong.

I think we need to perform a check inside OrderByColumn.bindOrderByColumn(), to find out whether the order by *expression* (not only column references) is same as the expression in RCL. If they are different we should raise that error if and only if (target instanceof SelectNode)=true and ( (SelectNode)target ).hasDistinct() =true.

I think this will make Derby to not pull-up an expression that is already there in RCL. Currently Derby pull-up j*2 expression in both occasions mentioned below:

          select distinct i from t order by j*2; // addedColumnOffset = 0
          select distinct j*2 from t order by j*2; // addedColumnOffset = 0 this ideally should be -1.

I like to get your view thoughts on this.

Thanks.

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