Skip to content

Instantly share code, notes, and snippets.

@portothree
Created September 14, 2021 14:34
Show Gist options
  • Select an option

  • Save portothree/8dddc9bc7b77d5b2f3ce50c7e8ad6f19 to your computer and use it in GitHub Desktop.

Select an option

Save portothree/8dddc9bc7b77d5b2f3ce50c7e8ad6f19 to your computer and use it in GitHub Desktop.
Retrieve Postgres constraints with `pg_catalog.pg_constraint`
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 rel.relname = 'table_name';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment