Thread: how to alter/drop check contraint?

how to alter/drop check contraint?

From
hubert depesz lubaczewski
Date:
the subject should be self-explanatory, but:
i have table:
create table a (b text check (length(b)<10));
and for some reason i want to drop this check or alter this to length(b)<20.
how can i do so?

or maybe using trigger in plpgsql will be better?
how to make trigger which will stop insert or update when something occurs?

depesz

-- 
hubert depesz lubaczewski
------------------------------------------------------------------------    najwspanialszą rzeczą jaką dało nam
nowoczesnespołeczeństwo,     jest niesamowita wręcz łatwość unikania kontaktów z nim ...
 


Re: how to alter/drop check contraint?

From
Stephan Szabo
Date:
There's no good way currently to drop the check constraint
really.  You probably can do it by removing the row for the
constraint from pg_relcheck and changing the pg_class row
for the table to have the correct number in relchecks.
In 7.1, you'd probably be able to add the check constraint
using ALTER TABLE ADD CONSTRAINT, but before that adding
the constraint would probably be difficult.

You're probably best off dumping the table, changing the
constraint and then restoring it.

[If you don't have any important data and you like the idea
of potentially causing yourself great deals of pain and suffering,
it might be possible to change the 10 to 20 by directly editing
the pg_relcheck row.  I have not attempted to do this though,
so I'm not sure it would work.]

Stephan Szabo
sszabo@bigpanda.com

On Wed, 20 Dec 2000, hubert depesz lubaczewski wrote:

> the subject should be self-explanatory, but:
> i have table:
> create table a (b text check (length(b)<10));
> and for some reason i want to drop this check or alter this to length(b)<20.
> how can i do so?
> 
> or maybe using trigger in plpgsql will be better?
> how to make trigger which will stop insert or update when something occurs?