Re: how to rename an unnamed uniqueness constraint?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Oliver Kullmann <O(dot)Kullmann(at)swansea(dot)ac(dot)uk>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to rename an unnamed uniqueness constraint?
Date: 2005-08-16 22:11:23
Message-ID: 1124230283.12095.94.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, 2005-08-16 at 19:01 +0100, Oliver Kullmann wrote:
>
> I have a table created with
>
> CREATE TABLE Current_academic_year
> (
> year_id INT REFERENCES Academic_years,
> CONSTRAINT year_id CHECK(year_id IS NOT NULL),
> active BOOL NOT NULL,
>
> UNIQUE(year_id),
> UNIQUE(active)
> )
> ;

> Now I need to drop the constraint "UNIQUE(active)".
> I tried variations of
>
> ALTER TABLE current_academic_year DROP CONSTRAINT "???"
>
> but I didn't succeed.
>
> I'm using version 7.4.8.
>
> Thanks in any case for your efforts!

\d current_academic_year

would show you that you have an index called
current_academic_year_active_key to enforce the unique constraint.

junk=# DROP INDEX current_academic_year_active_key;
ERROR: cannot drop index current_academic_year_active_key because constraint current_academic_year_active_key on table current_academic_year requires it
HINT: You may drop constraint current_academic_year_active_key on table current_academic_year instead.

Therefore, what you need to do is:

ALTER TABLE current_academic_year DROP CONSTRAINT current_academic_year_active_key;

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Elphick 2005-08-16 22:16:42 Re: how to rename an unnamed uniqueness constraint?
Previous Message Oliver Kullmann 2005-08-16 18:01:42 how to rename an unnamed uniqueness constraint?