pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Naomi Walker <nwalker@eldocomp.com>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: Grant syntax
Date: Mon, 07 Jul 2003 14:44:57 -0700
Message-ID: <3F09E9D9.60104@joeconway.com> (raw)
In-Reply-To: <5.1.0.14.2.20030707113005.024b1058@imap.eldocomp.com>
References: <5.1.0.14.2.20030707113005.024b1058@imap.eldocomp.com>

Naomi Walker wrote:
> 
> I need to grant access to all tables for all users on a particular 
> database.  I've tried:
> 
> GRANT ALL ON databasename to public;
> 
> But it complained the databasebase (relation) does not exist.  Do I have to 
> grant on each table in a separate statement?  I'm guessing not.
> 

The syntax for grant on a database is this:

GRANT { { CREATE | TEMPORARY | TEMP } [,...] | ALL [ PRIVILEGES ] }
      ON DATABASE dbname [, ...]
      TO { username | GROUP groupname | PUBLIC } [, ...]

but it doesn't appear that's what you were hoping for.

If you are trying to GRANT privileges to tables, I'm afraid you do have 
to do them one at a time, or write a function to automate it for you.

Here's a function that I've posted previously:

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




view thread (2+ messages)

Message-ID: <3F09E9D9.60104@joeconway.com>
Permalink:  ../3F09E9D9.60104@joeconway.com/
Also on:    postgresql.org/message-id/3F09E9D9.60104@joeconway.com

 · 

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: mail@joeconway.com, nwalker@eldocomp.com
  Subject: Re: Grant syntax
  In-Reply-To: <3F09E9D9.60104@joeconway.com>
  References: <5.1.0.14.2.20030707113005.024b1058@imap.eldocomp.com> <3F09E9D9.60104@joeconway.com>

* 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