haskell-beam / haskell-beam/beam

Run-time error "window function first_value requires an OVER clause"

Open
#703 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Haskell
Stars
635
Forks
193
PR merge metrics
No merged PRs in 30d

Description

This is my second attempt at writing code to select the latest version of each of a given type of document. Both have resulted in run-time errors. Here is the current offending version of the code, and below is the run-time error being produced.

For reference, the schema includes the following columns, which are used in the snippet below:

```hs
, type' :: Columnar f AgreementType
, version :: Columnar f Natural
```

```hs
-- | The latest version of each of the requested agreement types.
latestVersions ::
[AgreementType] ->
Q Postgres UserAccountServiceDb s (AgreementT (QExpr Postgres s))
latestVersions types = do
(expectedType, expectedVersion) <- aggregate_
(\Schema.Agreement.Agreement{..} -> (group_ type', firstValue_ version))
$ orderBy_ (desc_ . (.version))
$ filter_ (\Schema.Agreement.Agreement{..} -> type' `in_` (val_ <$> types))
$ all_ userAccountServiceDb.agreementTable
filter_ (\Schema.Agreement.Agreement{..} ->
type' ==. expectedType &&. version ==. expectedVersion)
$ all_ userAccountServiceDb.agreementTable
```

```hs
SqlError {sqlState = "42809", sqlExecStatus = FatalError, sqlErrorMsg = "window function first_value requires an OVER clause", sqlErrorDetail = "", sqlErrorHint = ""}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.