SHARE
TWEET

Untitled

a guest Jan 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.     'postgresql' AS dbms,
  3.     t.table_catalog,
  4.     t.table_schema,
  5.     t.table_name,
  6.     c.column_name,
  7.     c.ordinal_position,
  8.     c.data_type,
  9.     c.character_maximum_length,
  10.     n.constraint_type,
  11.     k2.table_schema,
  12.     k2.table_name,
  13.     k2.column_name
  14. FROM
  15.     information_schema.tables t
  16.     NATURAL
  17.     LEFT JOIN information_schema.columns c
  18.     LEFT JOIN (information_schema.key_column_usage k
  19.     NATURAL JOIN information_schema.table_constraints n
  20.     NATURAL
  21.     LEFT JOIN information_schema.referential_constraints r)
  22. ON c.table_catalog = k.table_catalog
  23. AND c.table_schema = k.table_schema
  24. AND c.table_name = k.table_name
  25. AND c.column_name = k.column_name
  26.     LEFT JOIN information_schema.key_column_usage k2 ON k.position_in_unique_constraint = k2.ordinal_position
  27.     AND r.unique_constraint_catalog = k2.constraint_catalog
  28.     AND r.unique_constraint_schema = k2.constraint_schema
  29.     AND r.unique_constraint_name = k2.constraint_name
  30. WHERE
  31.     t.TABLE_TYPE = 'BASE TABLE'
  32.     AND t.table_schema NOT IN ('information_schema', 'pg_catalog');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top