Revansidd / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

Case-sensitive column alias not found in group by #578

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A case-sensitive column alias does not seem to work in GROUP BY.

sql> select 1 "x" group by "x";    
Error: org.h2.jdbc.JdbcSQLException: Column "x" not found; SQL statement:
select 1 "x" group by "x" [42122-181]

The same column works fine in ORDER BY, or when not using quotes.

sql> select 1 "x" order by "x"; 
x
1
(1 row, 1 ms)

sql> select 1 x group by x;
X
1
(1 row, 0 ms)

This happens on 1.4.181 (2014-08-06).

Original issue reported on code.google.com by thilopl...@googlemail.com on 21 Aug 2014 at 3:10

GoogleCodeExporter commented 9 years ago
I tracked this down to this piece of code in Select.java at line 778

if (found < 0) {
    // special case: GROUP BY a column alias
    for (int j = 0; j < expSize; j++) {
        Expression e = expressions.get(j);
        if (db.equalsIdentifiers(sql, e.getAlias())) {
            found = j;
            break;
        }
    }

At this point in time sql == ""x"" and e.getAlias() == "x"
Note the extra quotes around the x in the sql variable.

But I have no idea how to fix it.

Original comment by noelgrandin on 25 Aug 2014 at 2:57

GoogleCodeExporter commented 9 years ago
This should be fixed in version 1.4.184.

Original comment by thomas.t...@gmail.com on 19 Dec 2014 at 8:46