tomjaguarpaw / haskell-opaleye

Other
602 stars 115 forks source link

Fix bug preventing `orderedAggregate` and `distinctAggregator` from being used together (one approach) #577

Closed shane-circuithub closed 11 months ago

shane-circuithub commented 12 months ago

This PR contains two commits.

The first commit adds a (failing) test case demonstrating the inability to combine orderedAggregate and distinctAggregator together, even in the limited cases allowed by PostgreSQL. The problem is that PostgreSQL only allows this if the expressions given in the ORDER BY clause match the expressions given as arguments to the aggregation function.

The second commit fixes this bug. It does so by adding Eq and Ord constraints to PrimExpr and using them to detect identical expressions anywhere within the Aggregate, and when we rename the expressions we maintain a Map of already-renamed expressions such that identical expressions will be renamed to the same symbol, fulfilling PostgreSQL's restriction.

shane-circuithub commented 12 months ago

This is based on the refactoring in #575.

shane-circuithub commented 11 months ago

Closing in favour of #578.