Query load and sort
I have a table
locations
with a geometry field :geom
(using ash_geo + geo_postgis). When a user lands on a page and geolocates, the list of locations should sort ASC based on the user location and show the distance away in miles.
My current query is:
and my calculation is:
The calculation works as expected but sorting does not (I believe it was working in a previous version). What am I missing and/or can I just calculate distance_miles
and just sort on that? IE:
(I tried this but it also did not work).4 Replies
🤔 that looks right to me. In what way does it not work?
(the first one, not the second one)
The locations appear to be sorting DESC or not at all
🤔 thats pretty strange...
Well, that query seems to be sorting them?
I think its the
:float
casting
Can you change distance_miles
to :decimal
?
It will change the result of your calculation though.Solution
Aha I found the issue was a
Enum.reduce
flipping the order later on