13 May,2022 by Rambler
Question: How can I list the Constraints on a PostgreSQL table ?
Answer: This script will list PostgreSQL constraints . It achieves the results via the pg_catalog.pg_constraint - which checks primary key, unique, foreign key, and exclusion constraints on tables.
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 = 'my_schema_name'
AND rel.relname = 'my_table_name';
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |