Skip to content

Instantly share code, notes, and snippets.

@maykelsb
Created October 10, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maykelsb/8ee8c146978908986a79b36d2dbb0d2e to your computer and use it in GitHub Desktop.
Save maykelsb/8ee8c146978908986a79b36d2dbb0d2e to your computer and use it in GitHub Desktop.
Consulta os objetos de banco de dados
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