Re: Postgresql -- initial impressions and comments

From: Joe Conway <mail(at)joeconway(dot)com>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: "j(dot)random(dot)programmer" <javadesigner(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Postgresql -- initial impressions and comments
Date: 2002-12-03 23:23:30
Message-ID: 3DED3CF2.9090606@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruno Wolff III wrote:
> On Mon, Dec 02, 2002 at 18:44:03 -0800,
> "j.random.programmer" <javadesigner(at)yahoo(dot)com> wrote:
>>5) There is no way to grant permissions on all tables
>>within a database to some user. You have to grant
>>permissions on each table one-by-one. What I want
>>to do (and mysql allows this) is something like:
>>
>>GRANT ALL on foodb.* to user_bar;
>
> You can get the list of tables from the system catalog and then issue
> grant statements for them. You could write a function to do this,
> do it in an application or write sql query output to a script which
> you then execute.

For example (not heavily tested!)

CREATE OR REPLACE FUNCTION grant_all(text) RETURNS TEXT AS '
DECLARE
rel record;
sql text;
BEGIN
FOR rel IN SELECT pg_catalog.quote_ident(c.relname) AS relname FROM
pg_catalog.pg_class c WHERE c.relkind = ''r'' AND c.relnamespace NOT IN
(select oid from pg_catalog.pg_namespace where nspname like ''pg\_%'') AND
pg_catalog.pg_table_is_visible(c.oid) LOOP
sql := ''grant all on '' || rel.relname || '' to '' || $1;
RAISE NOTICE ''%'', sql;
EXECUTE sql;
END LOOP;
RETURN ''OK'';
END;
' LANGUAGE 'plpgsql';

create user foo;
select grant_all('foo');

HTH,

Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2002-12-03 23:29:23 Re: [GENERAL] PostgreSQL Global Development Group Announces
Previous Message Justin Clift 2002-12-03 23:17:40 Re: PostgreSQL in Universities (Was: Re: 7.4 Wishlist)