2014-06-24 126 views
4

是否可以寫聚合函數的選擇結果

select min(next) from participant; 

爲esqueleto查詢?

UPDATE

我發現了min_功能。但是,代碼

nextMessageTime = 
    from $ \p -> min_ (p ^. ParticipantNext) 

顯然有一些模棱兩可的類型:

Could not deduce (Database.Esqueleto.Internal.Language.From 
        query expr backend (query (Entity (ParticipantGeneric backend0)))) 
    arising from the ambiguity check for ‘nextMessageTime’ 
from the context (Database.Esqueleto.Internal.Language.From 
        query expr backend (query (Entity (ParticipantGeneric backend2))), 
        Esqueleto query1 query backend1) 
    bound by the inferred type for ‘nextMessageTime’: 
      (Database.Esqueleto.Internal.Language.From 
       query expr backend (query (Entity (ParticipantGeneric backend2))), 
       Esqueleto query1 query backend1) => 
      query (Value (Maybe Int64)) 
    at Presta/DB/Queries.hs:(15,1)-(16,42) 
The type variable ‘backend0’ is ambiguous 
When checking that ‘nextMessageTime’ 
    has the inferred type ‘forall (query :: * -> *) 
           (expr :: * -> *) 
           backend 
           (query1 :: * -> *) 
           backend1 
           backend2. 
         (Database.Esqueleto.Internal.Language.From 
          query expr backend (query (Entity (ParticipantGeneric backend2))), 
          Esqueleto query1 query backend1) => 
         query (Value (Maybe Int64))’ 
Probable cause: the inferred type is ambiguous 
+1

是您的更新回答?不要將其編輯爲問題,將其作爲回答發佈 – Daenyth

+0

不是。問題是關於用esqueleto構造這個查詢。 –

+0

你的問題應該被編輯,以便更清楚你在問什麼 – Daenyth

回答

2

我設法得到這個工作使用持久的rawSql

nextMessageTime = do 
    [Single t] <- 
    rawSql 
     "SELECT min(next) FROM participant" 
     [] 
    return (t :: Int64) 

(但如果你介意的非窮盡模式重新複製此代碼。)