Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. SELECT con.relname AS child_table,
  2. att2.attname AS child_column,
  3. cl.relname AS parent_table,
  4. att.attname AS parent_column
  5. FROM (
  6. SELECT
  7. unnest(con1.conkey) AS parent,
  8. unnest(con1.confkey) AS child,
  9. con1.confrelid,
  10. con1.conrelid,
  11. cl_1.relname
  12. FROM
  13. pg_class cl_1,
  14. pg_namespace ns,
  15. pg_constraint con1
  16. WHERE
  17. con1.contype = 'f'::"char"
  18. AND cl_1.relnamespace = ns.oid
  19. AND con1.conrelid = cl_1.oid
  20. ) con,
  21. pg_attribute att,
  22. pg_class cl,
  23. pg_attribute att2
  24. WHERE
  25. att.attrelid = con.confrelid
  26. AND att.attnum = con.child
  27. AND cl.oid = con.confrelid
  28. AND att2.attrelid = con.conrelid
  29. AND att2.attnum = con.parent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement