I have the following setup:
create role test_user noinherit nologin;
create table test_me ( attr text );
create view v_test_me as select * from test_me;
create function fn() returns trigger language plpgsql as $$
begin
insert into test_me(attr) values (NEW.attr);
return NEW;
end; $$;
create trigger tg instead of insert on v_test_me
for each row execute procedure fn();
grant insert on v_test_me to test_user;
set role test_user;
insert into v_test_me(attr) values ('hello?');
Here I have a table and a view on top of it. The view has an instead-of-trigger. I am allowing test_user to insert into the view. But i get the following error:
ERROR: permission denied for table test_me
CONTEXT: SQL statement "insert into test_me(attr) values (NEW.attr)"
It looks like I do not have permission to execute an insert statement on the test_me table, which is expected. Is there any way I can allow user to insert into test_me table without directly granting them such permission?