https://supabase.com/ logo
#javascript
Title
# javascript
e

e0

08/15/2021, 4:36 PM
@User Thanks for responding. How come you doubt it would work? Here are the relevant docs and implementation. https://supabase.io/docs/postgrest/client/rpc#with-count-option https://github.com/supabase/postgrest-js/blob/master/src/lib/PostgrestRpcBuilder.ts#L23
Actually, looking at the provided example again in the docs:
.rpc('hello_world', { count: 'exact' })
. I'm not sure how this would set the header since it would end up setting the
params
object, which in turn sets the
body
.
I could verify this as well using a stored procedure that does not need params. Logging out the
headers
and
body
shows that the correct header is not set and the
body
is
{ count: 'exact' }
.
Ok, I think I have come to some sort of conclusion now. In
supabase/postgrest-js
, the
rpc('hello_world', { count: 'exact' })
would not work but
.rpc('hello_world', undefined, { count: 'exact' })
should work. For stored procedures that take params,
.rpc('hello', { name: 'world' }, { count: 'exact' })
should work as expected. In
supabase/supabase.js
, when using
const supabase = createClient()
, the
{ count: 'exact' }
never works because it is never passed to `postgrest-js`: https://github.com/supabase/supabase-js/blob/ebb9bb293c9843302629687850020a2d411a05ed/src/SupabaseClient.ts#L98-L101 I will try to add these findings to the relevant repos now.
b

burggraf

08/15/2021, 9:58 PM
Here's how I use count with `.select()`:
Copy code
const { data: countdata, error: counterror, count } = await supabase.from('tablename)
.select('*', { head: true, count: 'exact' });
So maybe you need to add the
head: true
part for
.rpc()
?
e

e0

08/15/2021, 10:02 PM
``select()` works fine for me too. I don't think
head
is supported at all for
.rpc()
. I would need the
data
anyways so I can't use
head: true
.
b

burggraf

08/15/2021, 11:59 PM
If you need the data anyway, can't you just do
data.length
?
e

e0

08/16/2021, 12:14 AM
Not if I want to use
range
for pagination. For example I want to return 50 rows but I want to know how many total matches there are. Anyways, like I mentioned in the message just before this thread, I already have a functional workaround. https://discord.com/channels/839993398554656828/869406062036529193/876472247919976509 Just wanted to see if others have noticed this too but after looking into it I’m almost certain that there are some bugs so I have reported them.
These issues seem to be resolved now.