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

Order by using computed column #321

Open
amosyuen opened this issue May 13, 2018 · 4 comments · May be fixed by #531
Open

Order by using computed column #321

amosyuen opened this issue May 13, 2018 · 4 comments · May be fixed by #531
Assignees
Labels

Comments

@amosyuen
Copy link

amosyuen commented May 13, 2018

When using mariadb dialect I try to order by a computed column, it instead tries to get the literal column on the table.

For example I have a computer column distance, trying to get that column and use it to order the table I get a query like this:

SELECT
  (ST_Distance(`homeConnec`.`lngLat`, POINT(0,0))) AS `distance`
FROM (
  SELECT `homeConnec`.*, count(*) OVER () AS `$total`
  FROM Home `homeConnec`
  ORDER BY `homeConnec`.`distance` ASC
) `homeConnec`
ORDER BY `homeConnec`.`distance`

Which throws an error Unknown column 'homeConnec.distance' as expected.

@amosyuen
Copy link
Author

I'm curious why it does a nested query for something that could easily be done without the nested query.

As far as I can tell there are two things that need to be done:

  1. Don't use the table prefix for computed columns in orderBy
  2. Either get rid of the nested query or also select the computed columns in the nested query

@amosyuen
Copy link
Author

Created #324 to address this

@arthurlataks
Copy link

Is there any chance this PR will be merged?

@nicoabie
Copy link
Contributor

nicoabie commented May 5, 2024

Please provide running example using https://github.com/join-monster/join-monster-sscce

@nicoabie nicoabie self-assigned this May 14, 2024
@nicoabie nicoabie linked a pull request May 14, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants