2013-11-17 4 views
3

selectDistinct, похоже, не работает для меня, это, вероятно, простая ошибка. запрос:Esqueleto `selectDistinct` не работает

info <- runDB $ 
     E.selectDistinct $ 
     E.from $ \(tp `E.InnerJoin` rnd `E.InnerJoin` h) -> do 
     E.on (rnd E.^. RoundId E.==. h E.^. HoleRound) 
     E.on (tp E.^. TpartTournament E.==. rnd E.^. RoundTourn) 
     E.where_ ((tp E.^. TpartTournament E.==. E.val tId)) 
     E.orderBy [E.asc (tp E.^. TpartId)] 
     return (tp, rnd, h) 

Я совершенно уверен, что это представляет собой SQL-запрос, который работает:

SELECT DISTINCT tpart.id, round.name, hole.hole_num, hole.score 
from tpart 
inner join round on round.tourn = tpart.tournament 
inner join hole on hole.round = round.id 
where tpart.tournament = 1; 

Для просмотра результатов у меня есть обработчик тестов, чтобы просто напечатать таблицу результатов. Обратите внимание, что для tpart 1, round 1, есть несколько отверстий 1 и отверстия 2. В postgresql SELECT DISTINICT удалены эти дубликаты.

 TpartId, RoundName, holeNum, HoleScore 

Key {unKey = PersistInt64 1}, round 1, 1, 6 
Key {unKey = PersistInt64 1}, round 1, 2, 4 
Key {unKey = PersistInt64 1}, round 1, 1, 6 
Key {unKey = PersistInt64 1}, round 1, 2, 4 
Key {unKey = PersistInt64 1}, round 1, 1, 6 
Key {unKey = PersistInt64 1}, round 1, 2, 4 
Key {unKey = PersistInt64 1}, round 2, 1, 3 
Key {unKey = PersistInt64 1}, round 2, 2, 5 
Key {unKey = PersistInt64 1}, round 2, 1, 3 
Key {unKey = PersistInt64 1}, round 2, 2, 5 
Key {unKey = PersistInt64 1}, round 2, 1, 3 
Key {unKey = PersistInt64 1}, round 2, 2, 5 
Key {unKey = PersistInt64 3}, round 1, 1, 6 
Key {unKey = PersistInt64 3}, round 1, 2, 4 
Key {unKey = PersistInt64 3}, round 1, 1, 6 
Key {unKey = PersistInt64 3}, round 1, 2, 4 
Key {unKey = PersistInt64 3}, round 1, 1, 6 
Key {unKey = PersistInt64 3}, round 1, 2, 4 
Key {unKey = PersistInt64 3}, round 2, 1, 3 
Key {unKey = PersistInt64 3}, round 2, 2, 5 
Key {unKey = PersistInt64 3}, round 2, 1, 3 
Key {unKey = PersistInt64 3}, round 2, 2, 5 
Key {unKey = PersistInt64 3}, round 2, 1, 3 
Key {unKey = PersistInt64 3}, round 2, 2, 5 

Извините за неразборчивость. Любая помощь будет оценена!

+0

Чтобы приблизиться к обнаружению проблемы, включите ведение журнала запросов, как указано в http://hackage.haskell.org/package/esqueleto-1.3.4.2/docs/Database-Esqueleto-Internal-Sql.html#v:toRawSql – MetaMemoryT

ответ

0

Ошибка была в том, что для определенного отверстия отверстие round И отверстие part отверстия должно совпадать с соответствующими частями. Кроме того, внутреннее соединение было избыточным в этой ситуации.