pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ang Chin Han <angch@bytecraft.com.my>
To: Rajesh Kumar Mallah <mallah@trade-india.com>
Cc: MaRcElO PeReIrA <gandalf_mp@yahoo.com.br>
Cc: pgsql-admin@postgresql.org
Subject: Re: Grant on several tables at once
Date: Tue, 05 Aug 2003 11:24:49 +0800
Message-ID: <3F2F2381.3060101@bytecraft.com.my> (raw)
In-Reply-To: <3F2ACA58.4050004@trade-india.com>
References: <3F2AC832.7090803@yahoo.com.br>
	<3F2ACA58.4050004@trade-india.com>

There was a review of a DB book on Slashdot some time ago, and parts of 
the book said that SELECTs are always safe since it never modifies 
anything in the db :)

This proves it wrong:


Try this (7.4Devel but should work on 7.3): Granting to several users.

-- pg_grant(priviledge, table, user)
create or replace function
   pg_grant(text, text, text) returns boolean language plpgsql as
'begin
execute ''grant '' || $1 || '' on '' || $2 || '' to '' || $3;
return true;
end;';

create or replace function
   pg_revoke(text, text, text) returns boolean language plpgsql as
'begin
execute ''revoke '' || $1 || '' on '' || $2 || '' from '' || $3;
return true;
end;';

-- Check if these are the tables you want:
select schemaname || '.' || tablename from pg_tables where
   schemaname = 'public';

-- Here we go:
select count(*) from pg_tables where
   schemaname = 'public' and
   pg_grant('select', schemaname || '.' || tablename, 'marcelo');

-- "Undo"
select count(*) from pg_tables where
   schemaname = 'public' and
   pg_revoke('select', schemaname || '.' || tablename, 'marcelo');

-- 
Linux homer 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 
GNU/Linux
  11:00am  up 222 days,  2:05,  5 users,  load average: 5.03, 5.08, 5.08

view thread (5+ messages)

Message-ID: <3F2F2381.3060101@bytecraft.com.my>
Permalink:  ../3F2F2381.3060101@bytecraft.com.my/
Also on:    postgresql.org/message-id/3F2F2381.3060101@bytecraft.com.my

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: angch@bytecraft.com.my, mallah@trade-india.com, gandalf_mp@yahoo.com.br
  Subject: Re: Grant on several tables at once
  In-Reply-To: <3F2F2381.3060101@bytecraft.com.my>
  References: <3F2AC832.7090803@yahoo.com.br> <3F2ACA58.4050004@trade-india.com> <3F2F2381.3060101@bytecraft.com.my>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox