[
https://issues.apache.org/jira/browse/DERBY-2351?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12575763#action_12575763
]
A B commented on DERBY-2351:
----------------------------
I haven't reviewed the latest patch yet, but regarding:
> select t1.id as idcolumn1, t1.id as idcolumn2 from t1 order by
> t1.idcolumn1, t1.idcolumn2;
>
> The behavior of the patch seems "correct", according to the rules we
> discussed.
> My feeling is that the query above deserves to be rejected
I agree with Bryan on this one, i.e. it seems reasonable to throw an error in
this case. I did try something similar on DB2 v8 and it throws an error:
select t1.i as a, t1.j as b from t1 order by t1.a, t1.b
SQL0206N "T1.A" is not valid in the context where it is used.
select t1.i as a, t1.j as b from t1 order by t1.i, t1.b
SQL0206N "T1.B" is not valid in the context where it is used.
select t1.i as a, t1.j as b from t1 order by t1.i, t1.j
<works as expected>
So there is a precedent, for what it's worth...
> 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, d2351_aliasing.diff,
> d2351_aliasing_checkQualifiedName.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.