X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 034C6B4399A for ; Mon, 7 Jul 2003 21:46:20 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 37131-02 for ; Mon, 7 Jul 2003 18:46:09 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 972B3B4316B for ; Mon, 7 Jul 2003 18:46:08 -0300 (ADT) Received: from [65.121.82.178] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 1820259; Mon, 07 Jul 2003 14:14:36 -0700 Message-ID: <3F09E9D9.60104@joeconway.com> Date: Mon, 07 Jul 2003 14:44:57 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Naomi Walker Cc: "pgsql-admin@postgresql.org" Subject: Re: Grant syntax References: <5.1.0.14.2.20030707113005.024b1058@imap.eldocomp.com> In-Reply-To: <5.1.0.14.2.20030707113005.024b1058@imap.eldocomp.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/80 X-Sequence-Number: 9421 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