|
From: Rafael J. Fernández-M. <rfe...@cs...> - 2008-06-05 01:10:30
|
Hello everybody!
I am getting a runtime error when I evaluate aggregates. For example,
consider:
query1 = do s <- table sailors
project (sid << _sum (s!sid))
"sid" is an attribute in table "sailors", of type Int (and NOT NULL).
When evaluating, I get a runtime error:
user error (The type of sid field can't be converted to SqlUnknown 246 type)
My intuition is that the type of a sum expression is not necessarily
Int, since you can always sum Doubles. Well, the next obvious step for
me was to rewrite the query and make the "receiving" column type a double:
data Doublefield = Doublefield
instance FieldTag Doublefield where fieldName _ = "doublefield"
doublefield :: Attr Doublefield Double
doublefield = mkAttr Doublefield
query2 = do s <- table sailors
project (doublefield << _sum (s!sid))
Oops, that won't compile, the inferred type of sum is indeed Int (or so
I'm told by GHC):
Couldn't match expected type `Double' against inferred type `Int'
Expected type: Expr Double
Inferred type: Expr Int
Strangely, count, max, and min do work. I wonder if (1) I'm missing
something, or (2) this is indeed an unexpected behaviour (given query1
passes the typechecker) that may be specific to MySQL...
Thanks,
RJFM
|