Created
October 10, 2016 15:00
-
-
Save maykelsb/8ee8c146978908986a79b36d2dbb0d2e to your computer and use it in GitHub Desktop.
Consulta os objetos de banco de dados
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
SELECT COUNT(1) AS qtd, | |
tipo | |
FROM (SELECT DISTINCT table_schema AS objeto, | |
'esquemas' AS tipo | |
FROM information_schema.tables | |
WHERE table_schema != 'pg_catalog' | |
AND table_schema != 'information_schema' | |
UNION ALL | |
SELECT table_schema || '.' || table_name AS objeto, | |
CASE WHEN table_type = 'BASE TABLE' THEN 'tabelas' | |
WHEN table_type = 'VIEW' THEN 'views' | |
ELSE '???' | |
END AS tipo | |
FROM information_schema.tables | |
WHERE table_schema != 'pg_catalog' | |
AND table_schema != 'information_schema' | |
UNION ALL | |
SELECT DISTINCT routine_schema || '.' || routine_name AS objeto, | |
'funcoes' AS tipo | |
FROM information_schema.routines | |
WHERE routine_schema != 'pg_catalog' | |
AND routine_schema != 'information_schema') a | |
GROUP BY tipo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment