\connect - postgres -- -- user postgres, NULL input -- select has_table_privilege(NULL,'pg_shadow','select'); -- -- user postgres, bad relname -- select has_table_privilege('postgres','pg_shad','select'); -- -- user postgres, bad usename -- select has_table_privilege('post','pg_shadow','select'); -- -- user postgres, bad priv_type -- select has_table_privilege('postgres','pg_shadow','sel'); -- -- user postgres, bad usesysid -- select has_table_privilege(-999999,'pg_shadow','update'); -- -- user postgres, bad rel oid -- select has_table_privilege('postgres',-999999,'rule'); -- -- user postgres, rel pg_shadow -- select has_table_privilege('postgres','pg_shadow','select'); select has_table_privilege('postgres','pg_shadow','insert'); select has_table_privilege(t2.usesysid,'pg_shadow','update') from (select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege(t2.usesysid,'pg_shadow','delete') from (select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege('postgres',t1.oid,'rule') from (select oid from pg_class where relname = 'pg_shadow') as t1; select has_table_privilege('postgres',t1.oid,'references') from (select oid from pg_class where relname = 'pg_shadow') as t1; select has_table_privilege(t2.usesysid,t1.oid,'select') from (select oid from pg_class where relname = 'pg_shadow') as t1,(select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege(t2.usesysid,t1.oid,'insert') from (select oid from pg_class where relname = 'pg_shadow') as t1,(select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege('pg_shadow','update'); select has_table_privilege('pg_shadow','delete'); select has_table_privilege(t1.oid,'select') from (select oid from pg_class where relname = 'pg_shadow') as t1; select has_table_privilege(t1.oid,'trigger') from (select oid from pg_class where relname = 'pg_shadow') as t1; -- -- create rel testtable -- create table testtable(f1 int, f2 text); -- -- user postgres, rel testtable -- select has_table_privilege('postgres','testtable','select'); select has_table_privilege('postgres','testtable','insert'); select has_table_privilege(t2.usesysid,'testtable','update') from (select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege(t2.usesysid,'testtable','delete') from (select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege('postgres',t1.oid,'rule') from (select oid from pg_class where relname = 'testtable') as t1; select has_table_privilege('postgres',t1.oid,'references') from (select oid from pg_class where relname = 'testtable') as t1; select has_table_privilege(t2.usesysid,t1.oid,'select') from (select oid from pg_class where relname = 'testtable') as t1,(select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege(t2.usesysid,t1.oid,'insert') from (select oid from pg_class where relname = 'testtable') as t1,(select usesysid from pg_user where usename = 'postgres') as t2; select has_table_privilege('testtable','update'); select has_table_privilege('testtable','delete'); select has_table_privilege(t1.oid,'rule') from (select oid from pg_class where relname = 'testtable') as t1; select has_table_privilege(t1.oid,'trigger') from (select oid from pg_class where relname = 'testtable') as t1; -- -- create new user, grant on testtable, and connect -- create user foo; grant select on testtable to foo; grant update on testtable to foo; grant rule on testtable to foo; \connect - foo -- -- user foo, rel pg_shadow -- select has_table_privilege('foo','pg_class','select'); select has_table_privilege('foo','pg_class','insert'); select has_table_privilege(t2.usesysid,'pg_class','update') from (select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege(t2.usesysid,'pg_class','delete') from (select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege('foo',t1.oid,'rule') from (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege('foo',t1.oid,'references') from (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(t2.usesysid,t1.oid,'select') from (select oid from pg_class where relname = 'pg_class') as t1,(select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege(t2.usesysid,t1.oid,'insert') from (select oid from pg_class where relname = 'pg_class') as t1,(select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege('pg_class','update'); select has_table_privilege('pg_class','delete'); select has_table_privilege(t1.oid,'select') from (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(t1.oid,'trigger') from (select oid from pg_class where relname = 'pg_class') as t1; -- -- user foo, rel testtable -- select has_table_privilege('foo','testtable','select'); select has_table_privilege('foo','testtable','insert'); select has_table_privilege(t2.usesysid,'testtable','update') from (select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege(t2.usesysid,'testtable','delete') from (select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege('foo',t1.oid,'rule') from (select oid from pg_class where relname = 'testtable') as t1; select has_table_privilege('foo',t1.oid,'references') from (select oid from pg_class where relname = 'testtable') as t1; select has_table_privilege(t2.usesysid,t1.oid,'select') from (select oid from pg_class where relname = 'testtable') as t1,(select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege(t2.usesysid,t1.oid,'insert') from (select oid from pg_class where relname = 'testtable') as t1,(select usesysid from pg_user where usename = 'foo') as t2; select has_table_privilege('testtable','update'); select has_table_privilege('testtable','delete'); select has_table_privilege(t1.oid,'select') from (select oid from pg_class where relname = 'testtable') as t1; select has_table_privilege(t1.oid,'trigger') from (select oid from pg_class where relname = 'testtable') as t1; -- -- Clean up -- \connect - postgres drop user foo; drop table testtable;