Advertisement
Revolucent

PostgreSQL Tables Without PKs

Mar 17th, 2017
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH relpub AS (
  2.   SELECT  r.oid
  3.       ,   r.relname
  4.   FROM    pg_class r
  5.           INNER JOIN pg_namespace n ON r.relnamespace = n.oid AND r.relkind = 'r' AND n.nspname = 'public'
  6. ),
  7. pk AS (
  8.   SELECT  r.oid
  9.   FROM    relpub r
  10.           INNER JOIN pg_index i ON r.oid = i.indrelid AND i.indisprimary
  11. )
  12. SELECT  r.relname
  13. FROM    relpub r
  14. WHERE   NOT EXISTS (
  15.           SELECT  oid
  16.           FROM    pk
  17.           WHERE   oid = r.oid
  18.         );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement