Created
February 17, 2010 13:22
-
-
Save Miuler/306596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- DAR PERMISOS A TODAS LAS TABLA DES UN SCHEMA | |
-- ============================================ | |
-- Funcion para asigar todos lo privilegios a un usuario | |
-- para todas las tablas, vistas, | |
-- que pertenecen aun esquema en particular. | |
-- | |
-- Esta función te lo resuelve: | |
CREATE OR REPLACE FUNCTION grant_all_privileges(p_user text, p_schema text) | |
RETURNS void AS | |
$BODY$ | |
DECLARE | |
objeto text; | |
BEGIN | |
FOR objeto IN | |
SELECT viewname FROM pg_views WHERE schemaname = p_schema | |
UNION | |
SELECT tablename FROM pg_tables WHERE schemaname = p_schema | |
UNION | |
SELECT relname FROM pg_statio_all_sequences WHERE schemaname = p_schema | |
LOOP | |
RAISE NOTICE 'Asignando todos los privilegios a % sobre %.%', p_user, p_schema, objeto; | |
EXECUTE 'GRANT ALL PRIVILEGES ON ' || p_schema || '.' || objeto || ' TO ' || p_user ; | |
END LOOP; | |
END; | |
$BODY$ | |
LANGUAGE 'plpgsql' VOLATILE; | |
--La usas así: | |
-- select grant_all_privileges('postgres', 'temp'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment