Is there a way to call an `rpc()` function with a ...
# javascript
s
Is there a way to call an
rpc()
function with a parameter that's an array (that's mapped to a custom postgres
enum[]
)? (Details in thread)
For example, I have an enum
enum_days_running
of
MON, TUE, WED, THU, FRI, SAT, SUN
. I also have a function,
get_services
, which has the following parameters: -
service_id text
-
filter_days_run enum_days_running[]
In Postgres, I can call this function with:
SELECT * FROM get_services('1234', array['MON', 'WED']::enum_days_running[]);
The results return as expected. If I try to call this via the supabase-js library via `.rpc()`:
Copy code
SupabaseClient.rpc("get_services", {
    service_id: "1234",
    filter_days_run: ['MON', 'WED']
})
The library returns the following:
Copy code
{
  hint: 'No function matches the given name and argument types. You might need to add explicit type casts.',
  details: null,
  code: '42883',
  message: 'function public.get_services(filter_days_run => text, service_id => text) does not exist'
}
I've tried to
JSON.stringify()
the
filter_days_run
when passing it to the RPC call, but this still causes the same error. Likewise, I also tried casting it to a string like
%7BMON,WED%7D
(according to the postgrest docs at https://postgrest.org/en/v7.0.0/api.html) but this also returns the same error. Any ideas?
SOLVED: Huh, so, the URL encoding (
%7B
and
%7D
) doesn't work, but replacing them with
{
and
}
respectively does