valderman / selda

A type-safe, high-level SQL library for Haskell
https://selda.link
MIT License
478 stars 58 forks source link

Do not isolate `distinct` to avoid missing renames #168

Closed TomMD closed 3 years ago

TomMD commented 3 years ago

Fix #165 by removing isolate from distinct calls.

Recall that queries in the form:

borked :: Query s (Col s Int)
borked = aggregate $ do
    _ <- distinct $ do
            t <- select people
            pure (t ! #msg)
    x <- distinct $ do
            t <- select people
            pure (t ! #name)
    pure (count x)

Cause Selda + the psql backend to fail. For a complete program see #165 and a throw-away psql such as docker run -p 5432:5432 --rm -e POSTGRES_PASSWORD=password -d postgres.

This query now succeeds along with make test and the make pgtest target. That said, I don't claim to have shoved the whole selda design into my head so viewing the PR with some suspicion is warranted.

TomMD commented 3 years ago

I've now added a regression test.

valderman commented 3 years ago

Very nice; thanks a lot for taking the time to diagnose and fix this!