Order by an aggregate sum that is automatically grouped? #4440
Unanswered
NicksPatties
asked this question in
Q&A
Replies: 1 comment
-
|
It is not possible to order by aggregates right now. We're planning on a solution by allowing ordering by the alias, but it's still pending/a work in progress. These are the related issues: #2730, #3625. The only ordering that can be done right now is to the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
PostgREST version: 13.0.0
I'm trying to order the results of an aggregate function that's been grouped by another column. Below is a sample of what I'm trying to do, and the error I get in response. In this example, I expect to see the sums of the total_prices for the past week, grouped by city, in descending order of those sums.
https://{base-url}/orders?select=total_price.sum(),city&sale_date=gte.2025-10-23&sale_date=lte.2025-10-30&order=total_price.desc{"code":"42803","details":null,"hint":null,"message":"column \"orders.total_price\" must appear in the GROUP BY clause or be used in an aggregate function"}total_priceis used in an aggregate function (total_price.sum()), unless I'm misunderstanding something. To be extra sure, I gave an alias to my aggregate, and got a similar error.https://{base-url}/orders?select=total_price_sum:total_price.sum(),city&sale_date=gte.2025-10-23&sale_date=lte.2025-10-30&order=total_price_sum.desc{"code":"42703","details":null,"hint":null,"message":"column orders.total_price_sum does not exist"}Can someone help me figure out how to order these items the way I want with PostgREST? Is it possible?
Beta Was this translation helpful? Give feedback.
All reactions