on master help sign in
Restore zero-based `indexed` (#214)

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.

commit36c2b1ef0c89d646b9d2618c23800861dd212759 authorShane <shane.obrien@circuithub.com> dateWed 2 Nov 2022, 18:35 (4 years ago) parentfd0b449
1 file changed+2−2
src/Rel8/Query/Indexed.hs+2−2
src/Rel8/Query/Indexed.hs+2−2
@@ -6,7 +6,7 @@ where
66-- base
77import Control.Applicative ( liftA2 )
88import Data.Int ( Int64 )
9−import Prelude ()
9+import Prelude
1010
1111-- rel8
1212import Rel8.Expr ( Expr )
@@ -18,4 +18,4 @@ import Rel8.Table.Window ( currentRow )
1818
1919-- | Pair each row of a query with its index within the query.
2020indexed :: Query a -> Query (Expr Int64, a)
21−indexed = window (liftA2 (,) rowNumber currentRow)
21+indexed = window (liftA2 (,) (subtract 1 <$> rowNumber) currentRow)