Re: Drop CHECK Constraint

From: Christian Ullrich <chris(at)chrullrich(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: Yan Cheng CHEOK <yccheok(at)yahoo(dot)com>
Subject: Re: Drop CHECK Constraint
Date: 2011-02-21 10:32:34
Message-ID: 4D623F42.50400@chrullrich.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

* Yan Cheng CHEOK wrote:

> I was wondering, is there any good way to drop a constraint? Currently, I am making assumption on the check constraint name.

> ALTER TABLE backup_table ADD CHECK (fk_lot_id = 99);
>
> If I want to drop the above CHECK constraint, I will do
>
> ALTER TABLE backup_table DROP CONSTRAINT backup_table_fk_lot_id_check; (I assume the constraint name will be backup_table_fk_lot_id_check)
>
> Is there any more robust way?

Name your constraints:

ALTER TABLE backup_table ADD CONSTRAINT lot_id_ck CHECK (fk_lot_id = 99)

Alternatively, you can get a list of constraints for your table from the
catalog:

SELECT conname
FROM pg_constraint
WHERE conrelid = 'backup_table'::regclass

You may have to add more conditions to the query.

--
Christian

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2011-02-21 10:58:00 Re: multiple tables as a foreign key
Previous Message Yan Cheng CHEOK 2011-02-21 09:39:10 Drop CHECK Constraint