Skip site navigation (1) Skip section navigation (2)

Re: Grant SELECT on all tables of a database

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Grant SELECT on all tables of a database
Date: 2007-05-29 19:51:42
Message-ID: 1180468302.15764.31.camel@linda.lfix.co.uk (view raw or flat)
Thread:
Lists: pgsql-admin
On Tue, 2007-05-29 at 10:21 -0700, Marsha Ramsey wrote:
> Hello all,
> 
> How do I GRANT SELECT to all my tables at once?  I have over 1026
> tables in this database...

I don't think there is any direct SQL command to do it. But try this:

psql -d your_database
        \t
        \a
        \o /tmp/sqlscript
        SELECT 'GRANT SELECT ON '  || schemaname || '.' || tablename ||
        ' TO PUBLIC ;'
          FROM pg_tables
          WHERE tableowner = CURRENT_USER;
        \o
        \i /tmp/sqlscript
        
-- 
Oliver Elphick                                          olly(at)lfix(dot)co(dot)uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
                 ========================================
   Do you want to know God?   http://www.lfix.co.uk/knowing_god.html


In response to

Responses

pgsql-admin by date

Next:From: Marsha RamseyDate: 2007-05-29 20:03:44
Subject: Re: Grant SELECT on all tables of a database
Previous:From: Marsha RamseyDate: 2007-05-29 17:21:02
Subject: Grant SELECT on all tables of a database

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group