-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
import Database.HaskellDB
import Database.HaskellDB.PrimQuery
import Database.HaskellDB.Query
import Database.HaskellDB.DBLayout
data Name' = Name'
instance FieldTag Name' where
fieldName _ = "name"
data Apples = Apples
instance FieldTag Apples where
fieldName _ = "age"
name :: Attr Name' String
name = mkAttr Name'
apples :: Attr Apples Int
apples = mkAttr Apples
applesTable :: Table (RecCons Name' (Expr String) (RecCons Apples (Expr Int) RecNil))
applesTable = Table "apples" [ ("name", AttrExpr "namecol")
, ("apples", AttrExpr "applecol")]
totalApples :: Query (Rel (RecCons Name' (Expr String) (RecCons Apples (Expr Int) RecNil)))
totalApples = do
t <- table applesTable `union` table applesTable
project (name << t!name #
apples << _sum(t!apples))
The aggregation is done before the union. It should be after.
*Main> putStrLn $ showSql totalApples
(SELECT namecol as name,
SUM(age3) as age
FROM apples as T1
GROUP BY namecol)
UNION
(SELECT namecol as name,
SUM(age3) as age
FROM apples as T1
GROUP BY namecol)
Metadata
Metadata
Assignees
Labels
No labels