Обсуждение: Grant syntax
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 informationthat is privileged, confidential and exempt from disclosure under applicable law. If you are not the intendedaddressee, 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 thismessage in error, please immediately advise the sender by reply email, and delete the message. Thank you.
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