Skip to content

Commit

Permalink
Restore zero-based indexed (#214)
Browse files Browse the repository at this point in the history
In #182 we introduced window functions, and also refactored `indexed` to use the new window function support via `rowNumber`.

However, previously `indexed` was zero-based, whereas PostgreSQL's `row_number()` function counts from one, so this change silently changed the behaviour of `indexed`.

This commit restores the previous behaviour.
  • Loading branch information
shane-circuithub committed Nov 2, 2022
1 parent fd0b449 commit 36c2b1e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Rel8/Query/Indexed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ where
-- base
import Control.Applicative ( liftA2 )
import Data.Int ( Int64 )
import Prelude ()
import Prelude

-- rel8
import Rel8.Expr ( Expr )
Expand All @@ -18,4 +18,4 @@ import Rel8.Table.Window ( currentRow )

-- | Pair each row of a query with its index within the query.
indexed :: Query a -> Query (Expr Int64, a)
indexed = window (liftA2 (,) rowNumber currentRow)
indexed = window (liftA2 (,) (subtract 1 <$> rowNumber) currentRow)

0 comments on commit 36c2b1e

Please sign in to comment.