Skip to content

Instantly share code, notes, and snippets.

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 bitlather/02e7e5c9950b60ece69ebc15be2aef06 to your computer and use it in GitHub Desktop.
Save bitlather/02e7e5c9950b60ece69ebc15be2aef06 to your computer and use it in GitHub Desktop.
-- PostgreSQL 9.3.14 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit
-- ============================================================================
-- Create a view to easily read table comments.
--
-- Returns:
--
-- A list of table names and comments associated with them.
--
-- Usage:
--
-- SELECT * FROM table_documentation;
--
-- ============================================================================
CREATE OR REPLACE VIEW table_documentation AS
SELECT
CAST(c.relname AS TEXT) AS table_name,
CAST(d.description AS TEXT) AS comment
FROM pg_class AS c
LEFT JOIN pg_description AS d ON (d.objoid = c.oid AND d.objsubid = 0)
WHERE c.relkind IN('r', 'v') AND d.description > ''
ORDER BY c.relname;
COMMIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment