Reputation: 2952
I have quite big database (Postgresql 9.3) with plenty of tables, constraints, etc. Some of the tables and constraint are automatically generated (some queries are also automatically generated).
Recently I found out that at some point there is a problem - one of the huge queries violates one constraint.
My question is: how can I easily find a definition of the constraint if I know it's name using SQL?
Upvotes: 1
Views: 172
Reputation:
The error message contains the constraint that was violated, using that name, you can easily retrieve the definition of that constraint:
e.g. if the constraint that was violated is named orders_customer_id_fkey
then the following show you that constraint:
select pg_get_constraintdef(c.oid, true)
from pg_constraint c
join pg_namespace n on n.oid = c.connamespace
where conname = 'orders_customer_id_fkey'
and n.nspname = 'public'
Upvotes: 2