postgrest-js icon indicating copy to clipboard operation
postgrest-js copied to clipboard

Add support for common aggregate functions(and distinct)

Open zlwaterfield opened this issue 3 years ago • 6 comments

Feature request

There are a bunch of commonly used Postgres methods that should be added:

  • COUNT(*)
  • AVG(number)
  • MIN(number)
  • MAX(number)

zlwaterfield avatar Sep 13 '20 21:09 zlwaterfield

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

kiwicopple avatar Sep 14 '20 03:09 kiwicopple

Forgot to mention it here, but COUNT is now an option when making request!

https://github.com/supabase/postgrest-js/pull/147

dshukertjr avatar Feb 23 '21 10:02 dshukertjr

@kiwicopple what's up with this, is it planned soon? Thanks

PH4NTOMiki avatar Jan 25 '22 12:01 PH4NTOMiki

@PH4NTOMiki Progress for this is being tracked at https://github.com/PostgREST/postgrest/issues/915#issuecomment-1002232582

steve-chavez avatar Jan 25 '22 18:01 steve-chavez

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

steve-chavez avatar Jul 01 '22 00:07 steve-chavez

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

jdgamble555 avatar Sep 26 '22 13:09 jdgamble555

3 years already and still this is open issue?

ckypper avatar Mar 10 '23 04:03 ckypper

Looking for this one too.

felixcheruiyot avatar Mar 26 '23 05:03 felixcheruiyot

Is there a plan for the 'distinct' function ?

JRB-y avatar Apr 29 '23 13:04 JRB-y

+1 for a distinct function. The supabase AI references it when searching docs, but the method doesn't exist.

rawestmoreland avatar Apr 29 '23 22:04 rawestmoreland

+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.

JRB-y avatar Apr 29 '23 22:04 JRB-y

+1 for common postgres functions

bizrockman avatar Jul 09 '23 16:07 bizrockman

Any update on this? I came from https://github.com/orgs/supabase/discussions/4549#discussioncomment-3459965

laubonghaudoi avatar Jul 12 '23 06:07 laubonghaudoi

+1 this would be really useful

aferrugento avatar Nov 13 '23 22:11 aferrugento

Hey, I need max() or min() would appreciate if someone smarter than me integrates it.

Shooteger avatar Dec 02 '23 02:12 Shooteger

Is there any ETA for this "important" feature ?

revskill10 avatar Dec 22 '23 20:12 revskill10

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 avatar Dec 22 '23 20:12 jdgamble555

@jdgamble555 Does supabase supports it in latest js-sdk yet ?

revskill10 avatar Dec 23 '23 11:12 revskill10

Looks like soon, not sure - https://supabase.com/blog/postgrest-12

J

jdgamble555 avatar Dec 23 '23 14:12 jdgamble555

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.

ConProgramming avatar Mar 05 '24 07:03 ConProgramming

Closing since support was already announced https://supabase.com/blog/postgrest-aggregate-functions :tada:

The typescript support can be tracked on another issue.

steve-chavez avatar Mar 06 '24 15:03 steve-chavez