Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C0F6D1337999 for ; Wed, 2 Feb 2011 16:55:56 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 70121-02 for ; Wed, 2 Feb 2011 20:55:49 +0000 (UTC) X-Greylist: delayed 00:15:17.625424 by SQLgrey-1.7.6 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id 703FA1336FA7 for ; Wed, 2 Feb 2011 16:55:49 -0400 (AST) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.69) (envelope-from ) id 1PkjV8-0001AH-OC for pgsql-sql@postgresql.org; Wed, 02 Feb 2011 12:40:30 -0800 Date: Wed, 2 Feb 2011 12:40:30 -0800 (PST) From: creationw To: pgsql-sql@postgresql.org Message-ID: <1296679230744-3368417.post@n5.nabble.com> Subject: How to checking the existance of constraints for a table? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.767 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201102/10 X-Sequence-Number: 35086 Hello, I have a sample table describe as follows, anyone knows how to checking the existence of a constraint? oviddb=# \d myTable Column | Type | Modifiers ---------+----------+----------- orderid | smallint | not null modelid | smallint | not null Indexes: "mytable_orderid_key" UNIQUE, btree (orderid) For example, how to know that myTable has a constraint with name "mytable_orderid_key"? I have this problem because when doing migration script, some old table may have this constraint or may not have. And after migration, we want to add this constraint: If I just run the command: alter table myTable add Unique (orderid) in the migration script, when the constraint exits, a new index will be created as "mytable_orderid_key1" UNIQUE, btree (orderid) So, it causes some duplication. oviddb=# \d myTable Column | Type | Modifiers ---------+----------+----------- orderid | smallint | not null modelid | smallint | not null Indexes: "mytable_orderid_key" UNIQUE, btree (orderid) "mytable_orderid_key1" UNIQUE, btree (orderid) My question becomes how to write sql statement with following semantecs if constraint unique (orderid) exists do nothing else alter table myTable add Unique (orderid) Thank you so much! -- View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-checking-the-existance-of-constraints-for-a-table-tp3368417p3368417.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.