Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jerbaroo opened this issue Mar 28, 2024 · 1 comment
Open
Labels

Comments

@jerbaroo
Copy link

jerbaroo commented Mar 28, 2024

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:

  , type' :: Columnar f AgreementType
  , version :: Columnar f Natural
-- | 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
SqlError {sqlState = "42809", sqlExecStatus = FatalError, sqlErrorMsg = "window function first_value requires an OVER clause", sqlErrorDetail = "", sqlErrorHint = ""}
@tathougies
Copy link
Collaborator

Can you run using one of the runBeam*Debug functions to output the debug statements? runBeamPostgresDebug logFn $ query?

@kmicklas kmicklas added the bug label Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants