Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masatomo/470171 to your computer and use it in GitHub Desktop.
Save masatomo/470171 to your computer and use it in GitHub Desktop.
SELECT d.nspname, b.relname, h.attname FROM pg_class b
JOIN pg_namespace d ON b.relnamespace=d.oid
join pg_attribute h on (b.oid=h.attrelid)
where b.relkind='r' and h.attname like '%_id'
and not exists (select true from pg_constraint e
join pg_class f on (f.oid=e.conrelid) where e.conrelid = b.oid and e.contype='f') and h.attnum > 0
and d.nspname not in ('pg_catalog', 'information_schema');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment