Posts Tagged ‘grant’

Grant privileges to all tables in a database for postgresql

Grant privileges to all tables in a database (select, update, insert, delete)
Eg:( Creating a read-only user in postgres)
–Function to grant access(select,insert,update,delete) to users

CREATE FUNCTION pg_grant(TEXT, TEXT, TEXT, TEXT)
RETURNS integer AS ‘
DECLARE obj record;
num integer;
BEGIN
num:=0;
FOR obj IN SELECT relname FROM pg_class c
JOIN pg_namespace ns ON (c.relnamespace = ns.oid) WHERE
relkind in (”r”,”v”,”S”) AND
nspname = $4 AND
relname LIKE [...]