Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Created December 16, 2022 20:24
Show Gist options
  • Save ryanguill/b1ae32337b458f830990133187178798 to your computer and use it in GitHub Desktop.
Save ryanguill/b1ae32337b458f830990133187178798 to your computer and use it in GitHub Desktop.
begin;
create table foo (
id uuid primary key not null,
updatable text,
not_updatable text
);
create user test_user;
GRANT insert on foo TO test_user;
GRANT select on foo TO test_user;
revoke update on foo from test_user;
grant update (updatable) on foo to test_user;
set role test_user;
select * from foo;
insert into foo (id, updatable, not_updatable)
values ('00000000-0000-0000-0000000000000001', 'original', 'original');
select * from foo;
update foo
set updatable = 'updated'
where id = '00000000-0000-0000-0000000000000001';
select * from foo;
update foo
set not_updatable = 'updated'
where id = '00000000-0000-0000-0000000000000001';
-- permission denied for table foo
update foo
set id = '00000000-0000-0000-0000000000000002'
where id = '00000000-0000-0000-0000000000000001';
-- permission denied for table foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment