1

I can use the pg_indexes view to get the SQL used to create an index (as in the sql in this question: How to get indexes, primary keys, and all constraints for a schema in PostgreSQL using standard sql).

Is there a way to get the SQL for constraints in PostgreSQL? I'm not seeing a pg_constraints table and the information I'm finding on line isn't pointing me to a solution, for example, these are some of the hits coming up when I Google the terms (postgresql get sql for constraint).

https://dba.stackexchange.com/questions/206562/postgres-read-constraints-definition

Postgres Check Constraint definition

https://www.geeksforgeeks.org/sql-query-to-display-all-the-existing-constraints-on-a-table/

John
  • 3,458
  • 4
  • 33
  • 54
  • 1
    "*I'm not seeing a pg_constraints table*" - [pg_constraint](https://www.postgresql.org/docs/current/catalog-pg-constraint.html) –  Jan 20 '23 at 20:10
  • pg_constraints that is parallel to pg_indexes (i.e. has the constraint_definition where pg_indexes has index_definition) – John Jan 20 '23 at 20:49
  • `select pg_get_constraintdef(oid) from pg_constraint where conname = ;` – Adrian Klaver Jan 20 '23 at 23:10

0 Answers0