Created
February 5, 2026 00:34
-
-
Save dewey/4ee0a9c03c272a836db9cd6f05b7d73a to your computer and use it in GitHub Desktop.
dump_tables.sql
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 json_agg( | |
| json_build_object( | |
| 'table', table_name, | |
| 'comment', table_comment, | |
| 'columns', columns | |
| ) ORDER BY table_name | |
| ) | |
| FROM ( | |
| SELECT | |
| c.relname as table_name, | |
| d_table.description as table_comment, | |
| ( | |
| SELECT json_agg( | |
| json_build_object( | |
| 'name', a.attname, | |
| 'type', pg_catalog.format_type(a.atttypid, a.atttypmod), | |
| 'comment', d.description | |
| ) ORDER BY a.attnum | |
| ) | |
| FROM pg_attribute a | |
| LEFT JOIN pg_description d ON d.objoid = a.attrelid AND d.objsubid = a.attnum | |
| WHERE a.attrelid = c.oid AND a.attnum > 0 AND NOT a.attisdropped | |
| ) as columns | |
| FROM pg_class c | |
| JOIN pg_namespace n ON n.oid = c.relnamespace | |
| LEFT JOIN pg_description d_table ON d_table.objoid = c.oid AND d_table.objsubid = 0 | |
| WHERE n.nspname = 'contentdb' AND c.relkind = 'r' AND c.relname != 'flyway_schema_history' | |
| ) tables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment