Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "COUNT(*)" in Supabase

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?

like image 865
dshukertjr Avatar asked Jan 07 '21 12:01

dshukertjr


2 Answers

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)

like image 130
kiwicopple Avatar answered Sep 18 '22 07:09

kiwicopple


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

like image 34
Shorn Avatar answered Sep 19 '22 07:09

Shorn