Follow dba-ninja.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

dba-ninja.com Links

Dba_db2_button

Sqlserver_dba_button

How to list PostgreSQL table constraints

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';

 

 

PostgreSQL cheatsheet


Author: Rambler (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to list PostgreSQL table constraints


dba-ninja.com