IF statements in RPC

Hello all! I'm new to Supabase and wanted to use the SQL editor to create a custom RPC. I'd like to use a conditional inside the function but I keep getting syntax errors. I've tried several options and below is my most recent attempt. Any and all help is appreciated! Thanks.

create or replace function handle_increment_stats (appt_id varchar, status varchar) returns void as $$
    if status = 'Pending'
    begin
      update clinic_stats
      set pending_appointments = pending_appointments + 1
      where id = appt.id
    end
$$ language sql volatile;
Was this page helpful?