Skip site navigation (1) Skip section navigation (2)

Re: how to rename an unnamed uniqueness constraint?

From: Oliver Kullmann <O(dot)Kullmann(at)swansea(dot)ac(dot)uk>
To: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>, pgsql-novice(at)postgresql(dot)org
Subject: Re: how to rename an unnamed uniqueness constraint?
Date: 2005-08-17 16:40:28
Message-ID: 20050817164028.GC14100@cs-wsok.swansea.ac.uk (view raw or flat)
Thread:
Lists: pgsql-novice
On Tue, Aug 16, 2005 at 11:11:23PM +0100, Oliver Elphick wrote:
> 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;
>

Thanks, that worked!
 
> TIP 3: Have you checked our extensive FAQ?
>                http://www.postgresql.org/docs/faq
> 

aha, looks good. I've added it to my bookmarks.

Oliver


In response to

pgsql-novice by date

Next:From: neil.saundersDate: 2005-08-18 15:31:10
Subject: My First Stored Procedure
Previous:From: Oliver KullmannDate: 2005-08-17 16:36:13
Subject: Re: how to rename an unnamed uniqueness constraint?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group