-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Request to support order-by with COLLATE #3683
Comments
I see, so you need to be able to do: SELECT * FROM projects ORDER BY name COLLATE "zh_CN"; And that's not possible with computed columns. The only way are views or functions.
It's not hard to enable it on the syntax but AFAICT doing an order with a different collation invalidates existing indexes (this is why the So we would need a way to restrict which collations can be applied. This is related to #2442 and #2805. |
Thanks @steve-chavez for the quick response.
I tried this in DB. It works.
Yes. I need to create indexes beforehand. The case is that I plan to support like 3 languages. And for those columns that support ordering by locale, I'll create indexes per locale.
In general, we could support all collations from |
We are using this argument ("potentially forcing slow queries") in a lot of cases. Until now all ideas to improve the situation were along the lines of either estimating the cost associated to the query and have a threshold, or to be able to block specific operations explicitly via config. How about we try to turn this around and enable additional operations only when a certain index is present? In the end, this might not be practical to do, especially with views involved, and we'll end up with looking at the cost estimation for a query again, but I think we should try to change our perspective here a bit. |
Yeah, I agree. If the index is present then we could enable the order collate. |
Requirement
I have a DB table
city
with columns -id
andname
. Thename
values are input by the end users of my application. So, it would be in different locales depending on the end user's locale.I want to provide a feature for my application to return the cities sorted by
name
in the end-user's locale. That is, the application would prepare the requestGET /city?order=name.collate.zh_cn
and send it to PostgREST service, and PostgREST service would return the cities sorted byname
in Chinese.It would be great if PostgREST could support
order=name.collate.zh_cn
.What I've tried
Create a View for
city
By creating a view
city_view
and adding a new columnname_zh COLLATE "zh_CN"
in the view, I can achieve the goal by sendingGET /city_view?order=name_zh
.However, I have lots of similar tables to support COLLATE sorting. There would be huge changes to creating views and adding columns.
Add computed column
name_zh
I tried to create a DB function to add a computed column
name_zh
tocity
. But it doesn't work.Any advice would be appreciated.
The text was updated successfully, but these errors were encountered: