cannot execute DELETE in a read-only transaction

Hi, I'm trying to delete an entry through a database function when the user calls this function, but I always get this error. I already checked select pg_is_in_recovery(); and show default_transaction_read_only;. I also tried to set set transaction read write; but then I'll get this error: set transaction read write;. Please help
4 Replies
NanoBit
NanoBit3y ago
Please show your code and the full error.
Lukas
LukasOP3y ago
React:
let { data, error } = await supabase
.rpc('removefriend', {
friendid: id
})
let { data, error } = await supabase
.rpc('removefriend', {
friendid: id
})
DB Function (with plv8):
return plv8.execute(
'DELETE FROM public.friends WHERE (public.friends.id = auth.uid() AND public.friends.friend = $1) OR (public.friends.id = $1 AND public.friends.friend = auth.uid());',
[friendid]
);
return plv8.execute(
'DELETE FROM public.friends WHERE (public.friends.id = auth.uid() AND public.friends.friend = $1) OR (public.friends.id = $1 AND public.friends.friend = auth.uid());',
[friendid]
);
Friends Table
| created_at | id | friend | request |
| created_at | id | friend | request |
@NanoBit
NanoBit
NanoBit3y ago
Sorry. I’m not so sure about plv8 as I have not used it before. You could also list the full function, whether it’s security definer or invoked etc
Lukas
LukasOP3y ago
no worries, i think I got it to work by creating the function through the terminal

Did you find this page helpful?