RCP Call

The RPC Call stage allows you to call Supabase stored functions (RPC) with parameters. This is useful for complex queries like aggregations, joins, or custom logic that can't be done with simple CRUD operations.

Input Parameters

ParameterVariableRequiredDescription
Function Name{{functionName}}YesName of the RPC function to call
Body Payload{{bodyPayload}}YesJSON string with function parameters


 

Output

OutputVariableDescription
RPC Result{{rpcResult}}Result returned by the function
Success{{success}}Boolean indicating if the call succeeded


 

Creating RPC Functions

Before using the RPC Call stage, you need to create functions in Supabase. Here are some examples:


 

Example 1: Get Records in Multiple Categories

Find IDs that exist in ALL specified categories:

CREATE OR REPLACE FUNCTION get_items_in_all_categories(category_ids int[])

RETURNS TABLE(item_id bigint) AS $$

BEGIN

  RETURN QUERY

  SELECT i.item_id FROM items i

  WHERE i.category_id = ANY(category_ids)

  GROUP BY i.item_id

  HAVING COUNT(DISTINCT i.category_id) = array_length(category_ids, 1);

END;

$$ LANGUAGE plpgsql;


 

Example 2: Get Categories by Item ID

Find all categories for a specific item:

CREATE OR REPLACE FUNCTION get_categories_by_item(item_id_input bigint)

RETURNS TABLE(category_id bigint) AS $$

BEGIN

  RETURN QUERY

  SELECT i.category_id::bigint FROM items i

  WHERE i.item_id = item_id_input;

END;

$$ LANGUAGE plpgsql;


 

Usage Examples

Example 1: Find Items in Multiple Categories

ParameterValue
functionNameget_items_in_all_categories
bodyPayload"{\"category_ids\": [1, 2, 3]}"

Result: Returns all item_ids that exist in ALL three categories


 

Example 2: Get Categories for an Item

ParameterValue
functionNameget_categories_by_item
bodyPayload"{\"item_id_input\": 123}"

Result: Returns all category IDs associated with item 123


 

Important Notes

  • Functions must be created in Supabase SQL Editor first
  • Use bigint for IDs to avoid type mismatch errors
  • Parameter names in bodyPayload must match function parameter names exactly
  • Great for complex queries: aggregations, joins, intersections

Was this article helpful?