Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure cosmos db alias column order by

I have written a select query in cosmos db which works fine. But in that query when i try to add order by column on a alias column it does not work. Here distance is an alias column What is the correct way to do it ?

SELECT c.id,c.type,c.name,c.latitude,c.longitude,c.location, ST_Distance(c.location, { 'type': 'Point', 'coordinates':[-112.215641, 33.181647]}) as distance FROM c WHERE ST_Distance(c.location, { 'type': 'Point', 'coordinates':[-112.215641, 33.181647]}) < 321868.8 ORDER BY c.distance ASC
like image 816
user1037747 Avatar asked Nov 16 '25 20:11

user1037747


1 Answers

Actually,we are told that we can only sort with properties of document, not derived values. Please see this link.You distance column is derived value,can't be used at order by.

“Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path”

I would suggest you sort the query result by yourself.For example,in .net code,you could use Sort function to sort the result by the column.

like image 148
Jay Gong Avatar answered Nov 18 '25 12:11

Jay Gong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!