From: | jsgarcia(at)seguridad(dot)unam(dot)mx |
---|---|
To: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | GRANT a varias tablas al mismo tiempo (Solucionado) |
Date: | 2009-12-01 23:54:49 |
Message-ID: | 20091201175449.4tmz9vhwgk488k04@correo.seguridad.unam.mx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda pgsql-es-fomento |
Gracias Álvaro, agradezco muchísimo tu tiempo para responder. Eso de
la función no se me había ocurrido hasta que Fernando me pasó
realmente el 95% o más de la solución, ya sólo le modifiqué muy poco
de tal forma que me quedó así:
CREATE OR REPLACE FUNCTION grant_all_privileges(p_user text)
RETURNS void AS
$BODY$
DECLARE
objeto text;
BEGIN
FOR objeto IN
SELECT viewname FROM pg_views WHERE schemaname='public'
UNION
SELECT tablename FROM pg_tables WHERE schemaname='public'
UNION
SELECT relname FROM pg_statio_all_sequences WHERE schemaname='public'
LOOP
RAISE NOTICE 'Asignando todos los privilegios a % sobre %.%', p_user,
public, objeto;
EXECUTE 'GRANT ALL PRIVILEGES ON public. ' || objeto || '
TO ' || p_user ;
END LOOP;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
_______________________________________________________________
Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> ha escrito:
> jsgarcia(at)seguridad(dot)unam(dot)mx escribió:
>> Hola muchachos, espero que todos estén muy bien.
>>
>> Como esto de estar dando privilegios tabla por tabla resulta muy
>> tedioso cuando se necesita hacer un ALL PRIVILEGES sobre todas las
>> tablas de nuestra base, se me ha ocurrido hacer una query así:
>>
>> GRANT ALL PRIVILEGES ON (SELECT viewname FROM pg_views WHERE
>> schemaname='public'
>> UNION
>> SELECT tablename FROM pg_tables WHERE schemaname='public'
>> UNION
>> SELECT relname FROM pg_statio_all_sequences WHERE
>> schemaname='public') TO prueba_permisos;
>
> Puedes construir una funcion en plpgsql que haga esto usando EXECUTE.
>
> --
> Alvaro Herrera Vendo parcela en Valdivia:
> http://valdivia.vivastreet.cl/loteos-lotes+valdivia/parcela-en-cabo-blanco--valdivia/19288372
> "How strange it is to find the words "Perl" and "saner" in such close
> proximity, with no apparent sense of irony. I doubt that Larry himself
> could have managed it." (ncm, http://lwn.net/Articles/174769/)
> --
> TIP 1: para suscribirte y desuscribirte, visita
> http://archives.postgresql.org/pgsql-es-ayuda
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
From | Date | Subject | |
---|---|---|---|
Next Message | Listas | 2009-12-01 23:59:53 | RE: Error en conexion |
Previous Message | Javier Fritz Alsite | 2009-12-01 23:45:56 | Re: Tunning PGSQL |
From | Date | Subject | |
---|---|---|---|
Next Message | Sergio Gabriel Rodriguez | 2009-12-02 01:00:58 | Re: GRANT a varias tablas al mismo tiempo |
Previous Message | Alvaro Herrera | 2009-12-01 21:37:48 | Re: GRANT a varias tablas al mismo tiempo |