Skip to content

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

Open
@jerbaroo

Description

@jerbaroo

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 = ""}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions