Reputation: 12528
I have this query (which works fine in mySQL cmdline), but when I run it in grails using executeQuery, I get this error: Bad format for Time
Here's my grails query:
def aveTimeToClose = OstFacTicket.executeQuery
("SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(TIMEDIFF(t.closed, t.created)))) as cl " +
"from OstFacTicket t WHERE t.created >= :sdate AND t.created <= :edate AND " +
"t.closed IS NOT NULL", [sdate:start, edate: end])
The stack trace errors are:
Error 2012-05-17 00:09:44,356 [http-bio-8080-exec-9]
ERROR util.JDBCExceptionReporter
- Bad format for Time '187:22:05' in column 1
| Error 2012-05-17 00:09:44,365 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver
Running on mySQL cmdline works fine:
mysql> SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(TIMEDIFF(t.closed, t.created)))) as cl
from ost_fac_ticket t where created > '2011-01-01 08:12:49' AND created <
'2011-12-31 10:12:49';
+-----------+
| cl |
+-----------+
| 187:22:05 |
+-----------+
Thanks, I appreciate any help.
Upvotes: 1
Views: 549
Reputation: 12528
I ended up following mu is too short's suggestion by just getting the query result in seconds and converting the number of seconds into the format I wanted using groovy.
Basically -
def aveTimeToClose = OstFacTicket.executeQuery("SELECT AVG(TIME_TO_SEC(TIMEDIFF(t.closed, t.created))) as cl "+
"from OstFacTicket t WHERE t.created >= :sdate AND t.created <= :edate AND t.closed IS NOT NULL", [sdate:start, edate: end])
The result aveTimeToClose is in seconds, which can easily be converted into datetime format.
Upvotes: 1