I'm trying to write a function which simply update...
# sql
a
I'm trying to write a function which simply updates a value in the database if called
Copy code
sql
create or replace function foo(id uuid) returns boolean as $$
  begin
    update tablename set bar='test';
    return true;
  end
$$ language plpgsql;
This returns
true
but the table rows are not updated. When commenting out everything except the update query, it updates as expected. Why?
s
What happens when you run that update inside the SQL Editor by itself?
a
It updates as expected
all rows.bar are changed to test
s
You have row level security (RLS) enabled?
a
is that relevant for rpc ?
I also think that it should throw an error in my dart code, if RLS would reject this. Right?
It returns
true
just fine with
200
status code
@User hmm, you're right. It only updates rows that the current user can see. I thought of functions as something like Firebase Cloud Functions. How can I prevent modification of certain columns but allow modification if done by a function?
s
Sorry I got distracted, you need to add security definer to your function creation and it should bypass RLS