Last active
December 18, 2015 10:10
-
-
Save DFrenkel/5766979 to your computer and use it in GitHub Desktop.
Recursively lists table inheritance in Postgres
This file contains 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 parentns.nspname as "parent schema", parent.relname as "parent table", childns.nspname "child schema", child.relname as "child table" | |
FROM pg_catalog.pg_inherits inh | |
INNER JOIN pg_catalog.pg_class as parent ON (inh.inhparent = parent.oid) | |
INNER JOIN pg_catalog.pg_namespace as parentns ON (parent.relnamespace = parentns.oid) | |
INNER JOIN pg_catalog.pg_class as child ON (inh.inhrelid = child.oid) | |
INNER JOIN pg_catalog.pg_namespace as childns ON (child.relnamespace = childns.oid) | |
ORDER BY parent.relname, child.relname; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment