Posted By

kmorey on 02/05/11


Versions (?)

Find foreign keys to a table in Postgres

 / Published in: SQL

  2. tc.constraint_name, tc.table_name, kcu.column_name,
  3. ccu.table_name AS foreign_table_name,
  4. ccu.column_name AS foreign_column_name
  5. FROM
  6. information_schema.table_constraints AS tc
  7. JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
  8. JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
  9. WHERE constraint_type = 'FOREIGN KEY' AND ccu.table_name='TABLE_NAME';

Report this snippet  

You need to login to post a comment.