Created
January 6, 2015 16:01
-
-
Save soc/88d7b06618ac98b4abf1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CREATE OR REPLACE FUNCTION create_user_roles() | |
RETURNS void | |
AS $$ | |
DECLARE | |
row RECORD; | |
role_name TEXT; | |
role_password TEXT; | |
BEGIN | |
FOR row IN (SELECT id FROM person) LOOP | |
role_name := concat('Role', row.id); | |
role_password := md5('row.id'); | |
EXECUTE $foo$CREATE ROLE $foo$ || quote_ident(role_name) || $foo$ WITH LOGIN NOSUPERUSER PASSWORD '$foo$ || role_password || $foo$' IN ROLE enduser;$foo$; | |
END LOOP; | |
END; | |
$$ LANGUAGE plpgsql | |
SECURITY DEFINER; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment