[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5173) hql - average returns double but looses the decimal part

Pascal Thivent (JIRA) noreply at atlassian.com
Sun May 9 03:15:51 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36989#action_36989 ] 

Pascal Thivent commented on HHH-5173:
-------------------------------------

This is also true for Derby/JavaDB. The documentation of the [AVG function|http://db.apache.org/derby/docs/dev/ref/rrefsqlj32693.html] is very clear about the behavior:

{quote}
The resulting data type is the same as the expression on which it operates (it will never overflow). The following query, for example, returns the INTEGER 1, which might not be what you would expect:

{code}
SELECT AVG(c1)
FROM (VALUES (1), (1), (1), (1), (2)) AS myTable (c1)
{code}

CAST the expression to another data type if you want more precision:

{code}
SELECT AVG(CAST (c1 AS DOUBLE PRECISION))
FROM (VALUES (1), (1), (1), (1), (2)) AS myTable (c1)
{code}
{quote}

> hql - average returns double but looses the decimal part
> --------------------------------------------------------
>
>                 Key: HHH-5173
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5173
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.5.0-Final
>         Environment: Database driver: hsqldb
> OS: Mac-Os
> Hibernate: 3.5.0-Final
>            Reporter: Sébastien Peters
>         Attachments: patch_unit_test.txt
>
>
> HQL:
>  select avg(r.rating) from Review r
>  for the values 2,2,2,1,2 it should return 1.8 instead of 1.0
> type of rating: integer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list