Pergunta

selectDistinct parece não estar funcionando para mim, provavelmente é um erro simples.A pergunta:

 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)  

Tenho certeza de que isso representa a consulta SQL que funciona:

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;

Para visualizar os resultados, tenho um manipulador de teste para apenas imprimir a tabela de resultados.Observe que para a parte 1, rodada 1, existem vários furos 1 e 2.No postgresql SELECT DISTINICT removeu essas duplicatas.

     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

Desculpe pela ilegibilidade.Qualquer ajuda seria apreciada!

Foi útil?

Solução

O erro foi que para um determinado Buraco, o buraco round E o Buraco part deve ser igual às respectivas partes.Além disso, a junção interna era redundante nessa situação.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top