Skip to content

Calling aggregate functions with supabase-js #626

Discussion options

You must be logged in to vote

You can resort to SQL functions if your query cannot be expressed purely in supabase-js.

Right now, calling the sum aggregate function and doing an inner join(embedding is done through a left join) is not possible with supabase-js directly. These capabilities are being worked on though.

Answering your questions:

how many PaymentIntents does a given author have?

create or replace function "TotalPaymentIntents"(author_id int)
returns bigint as $$
  select
    count(pi)
  from articles a
  join payment_intents pi on pi.article_id = a.id
  where a.author_id = $1;
$$ language sql stable;
// Then you can call it through supabase-js like:
const { data, error } = await db
  .rpc("TotalPaymentIn…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@kennethacohen
Comment options

Answer selected by kennethacohen
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants