Loading Depth Study
Preparing your workspace
Supabase RPC allows applications to invoke PostgreSQL functions for controlled database-side operations.
Some operations are easier or more reliable when they are performed inside PostgreSQL. Supabase can expose selected PostgreSQL functions through RPC calls. This is useful for calculations, transactional operations, reports, and database logic that should execute close to the stored data. Functions should be designed with clear input and output contracts and should not bypass security controls.
A course platform can use a PostgreSQL function to calculate a student's progress or perform a controlled multi-step update.
create or replace function get_course_count()
returns integer
language sql
as $$
select count(*)::integer
from courses
where published = true;
$$;
const { data, error } = await supabase.rpc('get_course_count');
if (error) {
throw error;
}
console.log(data);The RPC call returns the count of published courses calculated inside PostgreSQL.