postgrest-js
postgrest-js copied to clipboard
Add support for common aggregate functions(and distinct)
Feature request
There are a bunch of commonly used Postgres methods that should be added:
-
COUNT(*)
-
AVG(number)
-
MIN(number)
-
MAX(number)
Nice one.
Related for COUNT
, which will be coming soon: https://github.com/supabase/postgrest-js/issues/94
COUNT
will be simple because it's provided by PostgREST, however MIN/MAX/AVG
would require some work. We could potentially give developers the ability to query their database through pg-api, but we'll need to do some work on security if this is going to be exposed on the client.
Let's use this issue to list options after discussing with the team
Forgot to mention it here, but COUNT
is now an option when making request!
https://github.com/supabase/postgrest-js/pull/147
@kiwicopple what's up with this, is it planned soon? Thanks
@PH4NTOMiki Progress for this is being tracked at https://github.com/PostgREST/postgrest/issues/915#issuecomment-1002232582
An example of how this can be done now:
create or replace function max_value() returns int as $$
select max(my_column) from my_table;
$$ language sql;
const { data, error } = await supabase
.rpc('max_value')
References:
- https://supabase.com/docs/reference/javascript/rpc
- https://stackoverflow.com/questions/72814312/max-aggregate-function-syntax-to-be-called-by-the-supabase-client/72823179#72823179
Group By
is provided by postgres. Could we add this feature?
It should be relatively simple.
This is also very important because you can't subscribe to Views or Procedures. There is no work around for that.
J
3 years already and still this is open issue?
Looking for this one too.
Is there a plan for the 'distinct' function ?
+1 for a distinct function. The supabase AI references it when searching docs, but the method doesn't exist.
+1 for a distinct function. The supabase AI references it when searching docs, but the method doesn't exist.
Yea the AI confused me too.
+1 for common postgres functions
Any update on this? I came from https://github.com/orgs/supabase/discussions/4549#discussioncomment-3459965
+1 this would be really useful
Hey, I need max() or min() would appreciate if someone smarter than me integrates it.
Is there any ETA for this "important" feature ?
Is there any ETA for this "important" feature ?
It looks like it is in the latest version:
https://postgrest.org/en/stable/references/api/aggregate_functions.html
J
@jdgamble555 Does supabase supports it in latest js-sdk yet ?
Looks like soon, not sure - https://supabase.com/blog/postgrest-12
J
Awesome to see this official! https://supabase.com/blog/postgrest-aggregate-functions.
But Typescript support still missing. So for example get the error ParserError<"Expected identifier at
), label">[]
.
Would love to see fixed quick like #459 was.
Closing since support was already announced https://supabase.com/blog/postgrest-aggregate-functions :tada:
The typescript support can be tracked on another issue.