-
-
Notifications
You must be signed in to change notification settings - Fork 999
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
Feature Request: Ability to use cast syntax on order params #1651
Comments
I should add, if anyone stumbles upon this, that a workaround now is to create a view with the casted field in the definition and select from that:
(and i realize the proper fix for this specific case would be to just alter the column type in the table schema - this is a contrived example) |
Ah, this is a something we're not likely to include, because casting the left operand in a comparison would invalidate index usage. I wonder if that would be a concern for
Also, another option would be a computed/generated column. CREATE FUNCTION os_release_debversion(os) RETURNS debversion AS $$
SELECT $1.os_release_version::debversion;
$$ LANGUAGE SQL;
-- Then use like `GET /os?select=os_release_debversion&order=os_release_debversion |
I can understand that argument, but that presumes there is an index on the field at all - and in this case there is not. I'd argue that sometimes convenience sometimes trumps efficiency, and it's up to a user to know whether they will be triggering a slow query. |
My understanding is that, when we do The solution proposed by Steve is great. A simple one-liner SQL function like this will be inlined, so this should give exactly the result you want, without the need to create a view just for that. And it allows for much more complex scenarios as well. |
If for whatever reason the suggested solution does not work or there are other arguments in favor of the cast, feel free to reopen. For now, this seems settled, so I'm closing this. |
@gmichalec-pandora Has a point here. And that is indeed true, a CAST can be indexed and it would work through PostgREST.
That is the problem though. External API users don't necessarily know that, and malicious users could take advantage of unindexed casting to put a heavy load on your db. We'd need an |
Had another request for this:
The computed column way still applies. |
Environment
Description of issue
It seems that currently we aren't able to used casted fields in the order by param. For example, we have a field containing debian versions in string format like "8.10.1". Sorting these by string value won't return the desired result. However, we have a custom datatype 'debversion' that allows for proper sorting and comparison. However, attempting to order by a casted field returns an error.
(Expected behavior vs actual behavior)
Expected:
Actual:
(Steps to reproduce: Include a minimal SQL definition plus how you make the request to PostgREST and the response body)
may be a separate issue, but i also noticed you can't cast on where clauses either:
The text was updated successfully, but these errors were encountered: