Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created May 11, 2020 18:56
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 mattlockyer/84e031ea2b3fa1942d55a22076ea4b94 to your computer and use it in GitHub Desktop.
Save mattlockyer/84e031ea2b3fa1942d55a22076ea4b94 to your computer and use it in GitHub Desktop.
Postgres - get constraints from table
SELECT con.*
FROM pg_catalog.pg_constraint con
INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
INNER JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace
WHERE
nsp.nspname = '<schema name>'
AND rel.relname = '<table name>';
/* from: https://dba.stackexchange.com/a/214877/187757 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment