db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "A B (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-2351) ORDER BY with expression with distinct in the select list returns incorrect result
Date Mon, 03 Mar 2008 18:18:50 GMT

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

A B commented on DERBY-2351:
----------------------------

Hi Bryan, thanks for the patch.  Two minor comments:

1. Slight whitespace inconsistency (w.r.t. existing code) in ResultColumn.java
2. The following query (pulled from your modified orderby.out) currently fails with error
42X79:

      +ij> select distinct name as age from person order by person.age;
      +ERROR 42X79: Column name 'AGE' appears more than once in the result of the query expression.

It's good that the query fails, but I wonder if error 42X79 is the best error here?  From
the user's perspective there is only a single column in the query's result list, so the error
seems slightly misleading.  Instead, I think error 42879 (added as part of this issue) is
more appropriate, since the query attempts to order by a column that is not in the DISTINCT
list.  Any idea how hard it would be to catch that scenario and throw 42879 instead of 42X89?
 Would this just be a matter of checking to see if the column was "pulled" into the select
list and, if so, throwing 42879 instead of 42X79?  Or is it more complicated than that?  I
don't think this is a big deal at all--as long as there is an error I think it's fine--but
I thought I'd ask the question to see if you have already considered it.

> ORDER BY with expression with distinct in the select list returns incorrect result
> ----------------------------------------------------------------------------------
>
>                 Key: DERBY-2351
>                 URL: https://issues.apache.org/jira/browse/DERBY-2351
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.2.1.6, 10.2.2.0, 10.3.1.4
>         Environment: Any
>            Reporter: Yip Ng
>            Assignee: Bryan Pendleton
>             Fix For: 10.3.2.2, 10.4.0.0
>
>         Attachments: d2351_aliasing.diff, derby_2351.diff, derby_2351_v2.diff, reproTests.diff
>
>
> When distinct is in the select list and the query has order by with expression, the resultset
produced contains an additional column.  
> ij> create table t1 (c1 int, c2 varchar(10))
> 0 rows inserted/updated/deleted
> ij> insert into t1 values (1,'a'),(2,'b'),(3,'c');
> 3 rows inserted/updated/deleted
> select distinct c1, c2 from t1 order by c1;
> C1         |C2
> ----------------------
> 1          |a
> 2          |b
> 3          |c
> 3 rows selected
> ij> select distinct c1, c2 from t1 order by c1+1;
> C1         |C2        |3                                 <=====returns 3 columns,
incorrect result returned
> ----------------------------------
> 1          |a         |2
> 2          |b         |3
> 3          |c         |4
> 3 rows selected

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


Mime
View raw message