Skip to content

Instantly share code, notes, and snippets.

@os-ia
Created January 20, 2022 13:56
Show Gist options
  • Save os-ia/20aacb7b0b73f233d60e9acea5e40517 to your computer and use it in GitHub Desktop.
Save os-ia/20aacb7b0b73f233d60e9acea5e40517 to your computer and use it in GitHub Desktop.
Get all constraints of a PostgreSQL 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>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment