Skip to content

run-time error "column t0.res0 does not exist" #701

Open
@jerbaroo

Description

@jerbaroo

For a table that looks something like:

filename version foo

I am looking to write a query that returns, for each given filename, the row with greatest version for that filename.

Considering first the simple case of a query for a single filename, we can write:

selectLatest fname =
  runSelectReturningOne
    $ limit_ 1
    $ orderBy_ (desc_ . (.version))
    $ filter_ (Schema.File.name >>> (==. val_ fname))
    $ all_ db.fileTable

I am trying to adjust this to support multiple filenames:

selectLatest fnames =
  runSelectReturningList do
    -- for each filename in the given list..
    fname <- values_ $ val_ <$> fnames
    -- ..find the row with maximum version matching the filename.
    limit_ 1
      $ orderBy_ (desc_ . (.version))
      $ filter_ (Schema.File.name >>> (==. val_ fname))
      $ all_ db.fileTable

However this results in a run-time error:

SqlError {sqlState = "42703", sqlExecStatus = FatalError, sqlErrorMsg = "column t0.res0 does not exist", sqlErrorDetail = "", sqlErrorHint = "There is a column named \"res0\" in table \"t0\", but it cannot be referenced from this part of the query."}

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