db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dag H. Wanvik (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6009) Need stricter checking of ORDER BY clause in VALUES expressions
Date Thu, 27 Dec 2012 01:01:04 GMT

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

Dag H. Wanvik commented on DERBY-6009:
--------------------------------------

One approach would be to forbid order by expression if the expression does not contain a column
reference *or* is a simple integer constant.
It seems that even if the expression evaluates to a valid column number the result is wrong,
so I think we should just flag those:

> select i from t order by i; -- column 1
1 
2 
3 

> select i from t order by 1+0; -- i.e. column 1
2 
3 
1 

If a column is referenced it works as expected, though:
> select i from t order by i+0
1 
2 
3 

> select i from t order by -i+0
3 
2 
1

Can anyone think of a valid use cases for expressions that do not reference columns? I'll
have a look at what the standard says on this.



                
> Need stricter checking of ORDER BY clause in VALUES expressions
> ---------------------------------------------------------------
>
>                 Key: DERBY-6009
>                 URL: https://issues.apache.org/jira/browse/DERBY-6009
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.9.1.0
>            Reporter: Knut Anders Hatlen
>            Priority: Minor
>
> We only support column numbers in ORDER BY clauses in VALUES expression, as seen by this
error message:
> ij> values 1,2 order by 1+2;
> ERROR 42878: The ORDER BY clause of a SELECT UNION statement only supports unqualified
column references and column position numbers. Other expressions are not currently supported.
(errorCode = 30000)
> However, the checks let some unsupported expressions through and produce strange results.
For example:
> ij> values 1 order by 1+2;
> 1          |2          
> -----------------------
> 1          |3          
> 1 row selected
> It should probably have raised the same exception as the first query. And if not, the
result should only have had one column.
> And the next example should probably have raised a syntax error too, instead of a NullPointerException:
> ij> values 1 order by int(1);
> ERROR XJ001: Java exception: ': java.lang.NullPointerException'. (errorCode = 0)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message