2

I want to retrieve row count in Supabase.

I am guessing it would be something like this:

const { data, error } = await supabase
  .from('cities')
  .select('name', 'COUNT(*)')

Is this possible with Supabase?

dshukertjr
  • 8,227
  • 6
  • 33
  • 73

3 Answers3

4

For future visitors, we are working on this functionality with the PostgREST maintainer:

https://github.com/supabase/postgrest-js/issues/94

This is now released:

const { data, count } = supabase
  .from('countries')
  .select('*', { count: 'exact' })

(I'm a maintainer)

kiwicopple
  • 391
  • 3
  • 5
2

It is currently not supported yet, but there is a WIP issue on Github that would bring this feature to Supabase.

The code below has not been implemented in Supabase yet, but it might look something like this:

const { data, error, count } = await supabase
    .from('table')
    .select('*')
    .gt('id', 10)
    .count()
dshukertjr
  • 8,227
  • 6
  • 33
  • 73
1

As a workaround, you could write a standard Postgres stored procedure or function that returns the count then call that via the SB client.

https://supabase.io/docs/client/rpc

Shorn
  • 13,549
  • 11
  • 63
  • 124