Last active
November 9, 2023 22:52
-
-
Save shadyrudy/fccec8f92f0e63202bbc9d99fc988e37 to your computer and use it in GitHub Desktop.
PostgreSQL grant information. View postgres permission information
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
-- A Quick query to view postgresql grant information | |
-- Work in progress | |
SELECT | |
'TABLE' AS object_type, | |
grantee, | |
table_schema, | |
table_name, | |
privilege_type | |
FROM | |
information_schema.role_table_grants | |
WHERE | |
table_schema = (SELECT current_schema()) | |
UNION ALL | |
SELECT 'sequence' AS object_type, | |
grantee, | |
sequence_schema, | |
sequence_name, | |
privilege_type | |
FROM | |
information_schema.sequences | |
LEFT JOIN information_schema.role_table_grants | |
ON information_schema.sequences.sequence_name = information_schema.role_table_grants.table_name | |
where sequence_schema = (SELECT current_schema()) | |
UNION ALL | |
SELECT | |
'FUNCTION' AS object_type, | |
grantee, | |
specific_schema, | |
routine_name, | |
privilege_type | |
FROM | |
information_schema.role_routine_grants | |
WHERE | |
specific_schema = (SELECT current_schema()) | |
UNION ALL | |
SELECT | |
'VIEW' AS object_type, | |
grantee, | |
table_schema, | |
table_name, | |
privilege_type | |
FROM | |
information_schema.role_table_grants | |
WHERE | |
table_schema = (SELECT current_schema()) | |
AND table_name IN (SELECT viewname FROM pg_views WHERE schemaname = (SELECT current_schema())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment