Created
July 13, 2017 15:31
-
-
Save jms/a6cf657c35c314a717ce7040a97071c3 to your computer and use it in GitHub Desktop.
validate if a role name exists on postgresql , then execute statement
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
| DO $$ | |
| BEGIN | |
| IF NOT EXISTS (SELECT 1 FROM pg_catalago.pg_roles WHERE rolname = 'reader') THEN | |
| CREATE ROLE reader; | |
| END IF; | |
| END | |
| $$; | |
| GRANT SELECT ON tasks TO reader; | |
| -- | |
| DO $$ | |
| BEGIN | |
| IF EXISTS(SELECT count(*) FROM pg_catalago.pg_roles WHERE rolename = 'adm') THEN | |
| GRANT SELECT ON testview TO adm; | |
| END IF; | |
| END | |
| $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment