Index: java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj =================================================================== --- java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (revision 232906) +++ java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (working copy) @@ -986,7 +986,6 @@ switch (getToken(1).kind) { - case COUNT: case MAX: case AVG: case MIN: @@ -995,6 +994,11 @@ retval = true; break; + case COUNT: + // COUNT is not a reserved word + // This may eclipse use of COUNT as a function or a procedure that is probably what we want + if (getToken(2).kind == LEFT_PAREN) + retval = true; default: // Not a built-in aggregate - assume the first token is an // identifier, and see whether it is followed by " ( DISTINCT " @@ -8571,23 +8575,6 @@ { return aggExpr; } -| - /* - ** If we know we have a distinct, then we can catch - ** a user aggregate here; otherwise, we have to generate - ** a staticMethodNode and fix it up later. - */ - methodAliasString = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) - setQuantifier() value = additiveExpression(null, 0, false) - { - return (ValueNode) nodeFactory.getNode( - C_NodeTypes.AGGREGATE_NODE, - value, - methodAliasString, - Boolean.TRUE, - methodAliasString, - getContextManager()); - } } /* @@ -11594,7 +11581,6 @@ | tok = | tok = | tok = -| tok = | tok = | tok = | tok = @@ -11812,6 +11798,7 @@ | tok = | tok = | tok = + | tok = | tok = | tok = | tok = Index: java/testing/org/apache/derbyTesting/functionTests/tests/lang/nonreserved.sql =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/lang/nonreserved.sql (revision 232906) +++ java/testing/org/apache/derbyTesting/functionTests/tests/lang/nonreserved.sql (working copy) @@ -182,3 +182,28 @@ create index locks on locks(locks); drop table LOCKS; remove locks; + +-- making COUNT keyword nonreserved as fix for Derby- +create table count(i int); +drop table count; +create table t1 (count int); +drop table t1; +create table count(count int); +insert into count values (1); +select * from count; +select count from count; +select count from count where count=1; +select count.count from count; +prepare count as 'select * from count'; +create index count on count(count); +drop table count; +remove count; +create table t1(i int); +insert into t1 values -1,2,-3,4,-5,6,-7,8,-9,0; +create function count(i int) returns int no sql +external name 'java.lang.Math.abs' language java parameter style java; + +select count(*) from t1; +select count(i) from t1; +select * from t1 where count(i)=i; +drop table t1; Index: java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out (revision 232906) +++ java/testing/org/apache/derbyTesting/functionTests/master/nonreserved.out (working copy) @@ -401,4 +401,58 @@ ij> drop table LOCKS; 0 rows inserted/updated/deleted ij> remove locks; +ij> -- making COUNT keyword nonreserved as fix for Derby- +create table count(i int); +0 rows inserted/updated/deleted +ij> drop table count; +0 rows inserted/updated/deleted +ij> create table t1 (count int); +0 rows inserted/updated/deleted +ij> drop table t1; +0 rows inserted/updated/deleted +ij> create table count(count int); +0 rows inserted/updated/deleted +ij> insert into count values (1); +1 row inserted/updated/deleted +ij> select * from count; +COUNT +----------- +1 +ij> select count from count; +COUNT +----------- +1 +ij> select count from count where count=1; +COUNT +----------- +1 +ij> select count.count from count; +COUNT +----------- +1 +ij> prepare count as 'select * from count'; +ij> create index count on count(count); +0 rows inserted/updated/deleted +ij> drop table count; +0 rows inserted/updated/deleted +ij> remove count; +ij> create table t1(i int); +0 rows inserted/updated/deleted +ij> insert into t1 values -1,2,-3,4,-5,6,-7,8,-9,0; +10 rows inserted/updated/deleted +ij> create function count(i int) returns int no sql +external name 'java.lang.Math.abs' language java parameter style java; +0 rows inserted/updated/deleted +ij> select count(*) from t1; +1 +----------- +10 +ij> select count(i) from t1; +1 +----------- +10 +ij> select * from t1 where count(i)=i; +ERROR 42903: Invalid use of an aggregate function. +ij> drop table t1; +0 rows inserted/updated/deleted ij>