[
http://issues.apache.org/jira/browse/DERBY-147?page=comments#action_12422761 ]
Bernd Ruehlicke commented on DERBY-147:
---------------------------------------
OK got it perfectly working now.
I also refactored the getOrderByColumn(String, TableName) to call the
getOrderByColumn(String, TableName, int) instead of double the code. (See code
below)
After I have figured out why the source is distorted when I check it out with
svn I will apply the diff and make a patch. (That's I guess is why my fist
patch had so many spaces ...)
ij> select col1, col2, col1 from t order by col1;
COL1 |COL2 |COL1
----------------------------------
1 |one |1
2 |two |2
3 |three |3
3 rows selected
ij> select col1, col2, col1 from t order by col1, col2;
COL1 |COL2 |COL1
----------------------------------
1 |one |1
2 |two |2
3 |three |3
3 rows selected
ij> select col1, col2, col1, col1, col1, col2, col2 from t order by col1;
COL1 |COL2 |COL1 |COL1 |COL1 |COL2 |COL2
--------------------------------------------------------------------------------
1 |one |1 |1 |1 |one |one
2 |two |2 |2 |2 |two |two
3 |three |3 |3 |3 |three |three
3 rows selected
Codechange in ./engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
/**
* For order by, get a ResultColumn that matches the specified
* columnName
*
* @param columnName The ResultColumn to get from the list
* @param tableName The table name on the OrderByColumn, if any
* @param tableNumber The tableNumber corresponding to the FromTable
with the
* exposed name of tableName, if tableName != null.
*
* @return the column that matches that name.
*/
public ResultColumn getOrderByColumn(String columnName, TableName
tableName, int tableNumber)
throws StandardException
{
int size = size();
ResultColumn retVal = null, resultColumn;
for (int index = 0; index < size; index++)
{
resultColumn = (ResultColumn) elementAt(index);
/* The order by column is qualified, then it is okay to consider
* this RC if:
* o The RC is qualified and the qualifiers on the order
by column
* and the RC are equal().
* o The RC is not qualified, but its expression is a
ColumnReference
* from the same table (as determined by the
tableNumbers).
*/
if (tableName != null)
{
ValueNode rcExpr = resultColumn.getExpression();
if (rcExpr == null || !(rcExpr instanceof ColumnReference))
continue;
ColumnReference cr = (ColumnReference) rcExpr;
if( (! tableName.equals( cr.getTableNameNode())) &&
tableNumber != cr.getTableNumber())
continue;
}
/* We finally got past the qualifiers, now see if the column
* names are equal.
*/
if (columnName.equals( resultColumn.getName()) )
{
if (retVal == null)
{
retVal = resultColumn;
}
else if (index >= size - orderBySelect)
{// remove the column due to pullup of orderby item
removeElement(resultColumn);
decOrderBySelect();
break;
}
}
}
return retVal;
}
/**
* For order by, get a ResultColumn that matches the specified
* columnName
*
* @param columnName The ResultColumn to get from the list
* @param tableName The table name on the OrderByColumn, if any
*
* @return the column that matches that name.
*/
public ResultColumn getOrderByColumn(String columnName, TableName
tableName)
throws StandardException
{
return getOrderByColumn(columnName, tableName, -1);
}
> ERROR 42X79 not consistant ? - same column name specified twice
> ---------------------------------------------------------------
>
> Key: DERBY-147
> URL: http://issues.apache.org/jira/browse/DERBY-147
> Project: Derby
> Issue Type: Bug
> Components: SQL
> Reporter: Bernd Ruehlicke
> Attachments: derby-147-10.0.2.1.diff, derby-147.diff
>
>
> This happens from JDBC or ij. Here the output form ij>
> ij version 10.0
> CONNECTION0* - jdbc:derby:phsDB
> * = current connection
> ij> select a1.XXX_foreign, a1.native, a1.kind, a1.XXX_foreign FROM
> slg_name_lookup a1 ORDER BY a1.XXX_foreign;
> ERROR 42X79: Column name 'XXX_FOREIGN' appears more than once in the result
> of the query expression.
> But when removing the ORDER BY and keeping the 2 same column names it works
> ij> select a1.XXX_foreign, a1.native, a1.kind, a1.XXX_foreign FROM
> slg_name_lookup a1;
> XXX_FOREIGN
> |NATIVE
> |KIND |XXX_FOREIGN
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> 0 rows selected
> ij>
> So - it seams to be OK to specify the same column twice - as long as you do
> not add the ORDER BY clause.
> I woul dof course like that the system allows this - but at leats it should
> be consistant and either allow both or none of the two queries above.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira