Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Last active November 9, 2023 22:52
Show Gist options
  • Save shadyrudy/fccec8f92f0e63202bbc9d99fc988e37 to your computer and use it in GitHub Desktop.
Save shadyrudy/fccec8f92f0e63202bbc9d99fc988e37 to your computer and use it in GitHub Desktop.
PostgreSQL grant information. View postgres permission information
-- 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