Skip to content

Instantly share code, notes, and snippets.

@t18n
Created November 26, 2018 01:59
Show Gist options
  • Save t18n/bdb6c4aa07c60029912e4ad587e196b5 to your computer and use it in GitHub Desktop.
Save t18n/bdb6c4aa07c60029912e4ad587e196b5 to your computer and use it in GitHub Desktop.
Show all constraints PostgresSQL.md
SELECT conrelid::regclass AS table_from
, conname
, pg_get_constraintdef(c.oid)
FROM pg_constraint c
JOIN pg_namespace n ON n.oid = c.connamespace
WHERE contype IN ('f', 'p ')
AND n.nspname = 'public' -- your schema here
ORDER BY conrelid::regclass::text, contype DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment