Postgres Procedure RPC with JS API
I created the procedure below with the web console:
but when I try to call it with the SB JS API: , it throws the error: Am I missing something about how RPCs work?
16 Replies
I tried reloading the Schema Cache as it suggests, but it didn't seem to do anything, at least in solving my problem
You are using
CREATE PROCEDURE
instead of CREATE FUNCTION
, you need to use the latter. Basically procedures are called with a CALL
keyword and this is not how .rpc
works as it uses SELECT
which is what functions are called with.Like this? It seems to not like that I'm returning
void
. Is there a better way of defining that I don't want to return any data when successful?What error are you getting? you can definitely return void when creating a function. Please always provide the error you get as it helps others to understand what might be going on.
The error isn't very descriptive, though as to whether it was coming from
void
was a guess. Here's the error:
I assume it isn't that I need a semicolon after void
?
Sorry if the answer is really obvious, still trying to wrap my head around the basics in PSQL, and SQL in general.But the error didn't mention void being an issue.
Try
Yeah, it was just a guess, as I've had issues with ending a line incorrectly causing a Syntax Error in the next line before. My mistake!
Pushing an update now, let me see...
Ok, so that got me a little farther. It complained about
id
being ambiguous, so I changed it to CREATE FUNCTION transact(transId TEXT, created_at timestamptz, til TEXT, fra TEXT, beskrivelse TEXT, value float8)...
. Other than that, it is seems to have gone through(no errors). I reloaded the schema cache, but now I'm getting the not-found
error again...
This is when I try to call the Function from the JS RPC API.Can you check this section inside of your Supabase Dashboard and let me know if you see the function there https://app.supabase.com/project/_/database/functions

In the Dashboard it's showing
transid
and not transId
Yeah, just realized, I've had that happen with table names too. Even if I give them a capital name, they can only be queried via the JS API when I lowercase them...
You should always use lowercase and underscore _ when creating table names and column names, this is the recommended way by Postgres.
Is that a bug? Or is it intended to work that way?
Delete that function from the UI and then recreate it again.
Ok, it works now! Thank you for your help!
No problem, I'm happy you got it all working.