Skip to content

supabase-js rpc() fails with PGRST202 for parameter-less functions in React Native #1562

@brainforwarding

Description

@brainforwarding

When calling a PostgreSQL function that accepts no arguments using supabase.rpc('function_name') or supabase.rpc('function_name', {}) from a React Native (Expo) application, the call consistently fails with a PGRST202 error.

The error message indicates that PostgREST is searching for a function signature that includes a single unnamed text parameter, which is incorrect. This strongly suggests the supabase-js client is incorrectly serializing the request payload for parameter-less RPC calls within the React Native environment.

Direct API calls to the same endpoint using curl or the native fetch API with an empty JSON object payload ({}) succeed, confirming the issue is isolated to the supabase-js library's rpc() method.

Environment

  • supabase-js version: 2.49.4
  • react-native version: 0.76.9
  • expo version: ~52.0.47
  • Platform: iOS (reproducible in both Expo Go and with clean eas build development clients)

Steps to Reproduce

  1. Create a simple PostgreSQL function in your Supabase project that takes no arguments and returns a table. For example:
    CREATE OR REPLACE FUNCTION get_my_data()
    RETURNS TABLE(id uuid, email text) AS $$
    BEGIN
      RETURN QUERY SELECT id, email FROM auth.users LIMIT 2;
    END;
    $$ LANGUAGE plpgsql SECURITY DEFINER;
  2. In a React Native application using the environment specified above, attempt to call this function using supabase-js:
    // Attempt 1: Fails
    const { data, error } = await supabase.rpc('get_my_data', {});
    
    // Attempt 2: Also fails
    const { data, error } = await supabase.rpc('get_my_data');
  3. Observe the console logs for the error.

Expected Behavior

The rpc() call should succeed without errors and return the data from the PostgreSQL function.

Actual Behavior

Both attempts to call the RPC fail with the following PGRST202 error, indicating the request payload was malformed into a single text parameter:

{
  "code": "PGRST202",
  "details": "Searched for the function public.get_my_data with a single unnamed text parameter, but no matches were found in the schema cache.",
  "hint": null,
  "message": "Could not find the function public.get_my_data in the schema cache"
}

Workaround

Bypassing the supabase-js rpc() method and using a manual fetch call with the correct headers and an explicitly empty JSON object body works as expected. This proves the backend and authentication are configured correctly.

// This code successfully calls the RPC and retrieves data
const { data: { session } } = await supabase.auth.getSession();

const response = await fetch(`YOUR_SUPABASE_URL/rest/v1/rpc/get_my_data`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'apikey': 'YOUR_SUPABASE_ANON_KEY',
    'Authorization': `Bearer ${session.access_token}`,
  },
  body: JSON.stringify({}),
});

const responseData = await response.json(); // This succeeds

Additional Context

  • A direct curl command against the RPC endpoint with -d '{}' succeeds.
  • The issue persists in clean, production-like builds (eas build), ruling out stale client-side caches as the cause.
  • Attempting to pass dummy named parameters (e.g., { dummy_param: 'dummy_value' }) still results in the exact same error. This suggests the entire parameter object is being ignored or replaced before the request is sent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions