-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: CASE statement not supported in SQL count function?
PostPosted: Wed Nov 19, 2008 7:51 pm 
Newbie

Joined: Wed Aug 24, 2005 1:43 pm
Posts: 10
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 11:38 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Use session.createSQLQuery() and then query.setEntity() when you need to use SQL code that has no HQL equivalent.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.