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

Bug: Sort order not preserved in distinct query #93

Closed
frankdugan3 opened this issue May 5, 2022 · 0 comments
Closed

Bug: Sort order not preserved in distinct query #93

frankdugan3 opened this issue May 5, 2022 · 0 comments
Labels
bug Something isn't working needs review

Comments

@frankdugan3
Copy link
Contributor

Describe the bug

When sorting with distinct, the query builder seems to add an extraneous ORDER BY that conflicts with the specified sort direction.

To Reproduce

query
|> Ash.Query.sort(job_no: :desc)
|> Ash.Query.distinct(:job_no)
|> Ash.Query.limit(20)
SELECT
  DISTINCT ON (e0."job_no") e0."job_no",
  -- ...
  e0."id"
FROM
  "e2_routing" AS e0 WINDOW "order" AS (
    ORDER BY
      e0."job_no" DESC
  )
ORDER BY
  e0."job_no",
  e0."job_no" DESC
LIMIT
  $ 1 [ 20 ]

The query generated without distinct is as expected:

query
|> Ash.Query.sort(job_no: :desc)
|> Ash.Query.limit(20)
SELECT
  e0."job_no",
  -- ...
  e0."id"
FROM
  "e2_routing" AS e0 WINDOW "order" AS (
    ORDER BY
      e0."job_no" DESC
  )
ORDER BY
  e0."job_no" DESC
LIMIT
  $ 1 [ 20 ]

Expected behavior

Sort/direction should be preserved through a distinct query.

** Runtime

  • Elixir 1.13.4
  • Erlang OTP 24
  • OS 5.4.188-1-MANJARO (Linux)
  • Ash 1.52.0-rc.1
  • ash_postgres 0.42.0-rc.0
@frankdugan3 frankdugan3 added bug Something isn't working needs review labels May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs review
Projects
None yet
Development

No branches or pull requests

1 participant