prowdsponsor / esqueleto

Bare bones, type-safe EDSL for SQL queries on persistent backends.
http://hackage.haskell.org/package/esqueleto
BSD 3-Clause "New" or "Revised" License
177 stars 51 forks source link

mixing up order of orderBy clause passes typechecking, produces bad sql #142

Open mwotton opened 7 years ago

mwotton commented 7 years ago
      select $ from $ \(jobs,jobUpdates) ->
      distinctOn [ don (jobUpdates ^. JobUpdateJobId) ] $ do
        orderBy [ desc (jobUpdates ^. JobUpdateAt)
                , desc (jobUpdates ^. JobUpdateJobId) ]
        where_ (jobs ^. JobCompanyId ==. val companyk)
        where_ (jobUpdates ^. JobUpdateJobId ==. jobs ^. JobId)
        return jobUpdates

with the error message

       uncaught exception: SqlError (SqlError {sqlState = "42P10", sqlExecStatus = FatalError, sqlErrorMsg = "SELECT DISTINCT ON expressions must match initial ORDER BY expressions", sqlErrorDetail = "", sqlErrorHint = ""})

I understand why this is happening, but it'd be really nice if typechecked code producing invalid SQL was less of a regular occurrence in my workflow.