Created
October 3, 2023 14:44
-
-
Save jziggas/fbd2a7cd01e1a00c4b3435440f9e3f35 to your computer and use it in GitHub Desktop.
Drop all policies on a given table in PostgreSQL
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 drop_all_policies_on_table( | |
target_schema text, | |
target_table_name text | |
) RETURNS void LANGUAGE plpgsql AS $$ | |
DECLARE | |
policy_name text; | |
sql_text text; | |
BEGIN | |
FOR policy_name IN ( | |
SELECT policyname | |
FROM pg_policies | |
WHERE schemaname = target_schema AND tablename = target_table_name | |
) | |
LOOP | |
sql_text := format('DROP POLICY "%s" on %I.%I', policy_name, target_schema, target_table_name); | |
RAISE NOTICE '%', sql_text; | |
EXECUTE sql_text; | |
END LOOP; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment