Created
October 28, 2019 14:30
-
-
Save code-shoily/6cb2584b77e05d68e2d383be3c71fa34 to your computer and use it in GitHub Desktop.
Find all tables that has 'auth_user' as Foreign Key
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 | |
(select | |
cls.relname | |
from | |
pg_class cls | |
where | |
cls.oid = cnstr.conrelid) as tbl, | |
(select | |
array_agg(attname) | |
from | |
pg_attribute | |
where | |
attrelid = cnstr.conrelid and ARRAY[attnum] <@ cnstr.conkey) as fk_col, | |
(select | |
cls.relname | |
from | |
pg_class cls | |
where | |
cls.oid = cnstr.confrelid) as target | |
from pg_constraint cnstr | |
where | |
cnstr.confrelid = (select oid from pg_class where relname = 'auth_user'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment