Good evening,
I need to execute a query using something like (SQL is obviously simplified a lot to focus on issue - I need count(distinct CASE..) combo)
select count(distinct (CASE WHEN obj.id < 1000 then 1 else null) )
from object obj
Stack trace is below.
The equivalent runs fine in SQL as aggregate functions support case statement.
select count(distinct (CASE WHEN ID < 1000 THEN 1 ELSE 0 END))
from TABLE
This looks like a bug in the parser?
Thanks,
Seb
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.2.6
Mapping documents:
N/A
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
18:38:52,841 ERROR PARSER:33 - line 1:23: unexpected token: (
18:38:52,857 ERROR PARSER:33 - line 1:29: unexpected token: WHEN
18:38:52,857 ERROR PARSER:33 - line 1:61: unexpected token: THEN
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 23 XXXX
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
Name and version of the database you are using:
Sybase 12.5
The generated SQL (show_sql=true):
Failed
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html