pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Grant syntax
2+ messages / 2 participants
[nested] [flat]

* Grant syntax
@ 2003-07-07 18:33  Naomi Walker <nwalker@eldocomp.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Naomi Walker @ 2003-07-07 18:33 UTC (permalink / raw)
  To: pgsql-admin



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.

Naomi

-- CONFIDENTIALITY NOTICE --

This message is intended for the sole use of the individual and entity to whom it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not the intended addressee, nor authorized to receive for the intended addressee, you are hereby notified that you may not use, copy, disclose or distribute to anyone the message or any information contained in the message. If you have received this message in error, please immediately advise the sender by reply email, and delete the message. Thank you.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Grant syntax
@ 2003-07-07 21:44  Joe Conway <mail@joeconway.com>
  parent: Naomi Walker <nwalker@eldocomp.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Joe Conway @ 2003-07-07 21:44 UTC (permalink / raw)
  To: Naomi Walker <nwalker@eldocomp.com>; +Cc: pgsql-admin

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-07-07 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-07-07 18:33 Grant syntax Naomi Walker <nwalker@eldocomp.com>
2003-07-07 21:44 ` Joe Conway <mail@joeconway.com>

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