Challenge - 5 Problems
RPC Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediateWhat is the output of this Supabase RPC call?
You have a Postgres function named
If the
get_user_count that returns the total number of users in the users table. You call it via Supabase RPC like this:const { data, error } = await supabase.rpc('get_user_count');
console.log(data);If the
users table has 42 rows, what will console.log(data) output?Supabase
const { data, error } = await supabase.rpc('get_user_count');
console.log(data);Attempts:
2 left
💡 Hint
Supabase RPC returns an array of results by default.
✗ Incorrect
Supabase RPC calls return an array of rows from the Postgres function. If the function returns a single scalar value, it is wrapped in an array. So the output is [42].
❓ Configuration
intermediateWhich option correctly calls a Postgres function with parameters via Supabase RPC?
You have a Postgres function
get_user_by_email(email text) that returns user info for a given email. Which of these Supabase RPC calls correctly passes the email parameter?Attempts:
2 left
💡 Hint
Supabase RPC expects parameters as an object with keys matching function arguments.
✗ Incorrect
Supabase RPC requires parameters as an object where keys match the Postgres function's argument names. Option C correctly passes { email: 'test@example.com' }.
❓ Architecture
advancedWhat is the best way to secure a Postgres function exposed via Supabase RPC?
You want to expose a Postgres function via Supabase RPC but restrict access only to authenticated users. Which approach ensures this?
Attempts:
2 left
💡 Hint
Supabase uses RLS policies to control data access per user.
✗ Incorrect
Supabase enforces security mainly via Row Level Security policies on tables. Functions should rely on RLS and JWT authentication to restrict access properly.
✅ Best Practice
advancedWhich practice improves performance when calling Postgres functions via Supabase RPC?
You have a function that returns a large dataset. Which practice helps reduce latency and improve performance when calling it via Supabase RPC?
Attempts:
2 left
💡 Hint
Fetching smaller chunks reduces data transfer and speeds up response.
✗ Incorrect
Using LIMIT and OFFSET in the function to paginate results reduces data size per call, improving performance and user experience.
🧠 Conceptual
expertWhat error occurs if you call a non-existent Postgres function via Supabase RPC?
You call
await supabase.rpc('non_existing_function'); but the function does not exist in the database. What error will Supabase return?Supabase
await supabase.rpc('non_existing_function');
Attempts:
2 left
💡 Hint
Error code 42883 means function not found in Postgres.
✗ Incorrect
Postgres error code 42883 indicates a missing function. Supabase returns this error when the RPC function does not exist.
