How to get the list of postgres check constraints of a table?

424    Asked by Amitraj in SQL Server , Asked on Oct 4, 2022

How to list all constraints (Primary key, check, unique mutual exclusive, ..) of a table in PostgreSQL?

Answered by Alexander Coxon

Postgres check Constraints can be retrieved via 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 nsp.nspname = ''
             AND rel.relname = '';

Replace with the name of your schema and

with the name of your table.



Your Answer