Diabling constraints

Started by Linh Luongover 24 years ago2 messagesgeneral
Jump to latest
#1Linh Luong
linh.luong@computalog.com

Hi,

I am wondering is there any way of disabling constraints that was
created after the table itself was created.

I know I can drop the trigger that the constraint creates. However, I
need to make this change in several postgres database and it seems like
the the tgname that is required to remove the constraint is generate by
the system so I can't just go
drop trigger "<tgname>" on <tablename> because tgname is different in
all the database I need to modify.

Any ideas in disabling or removing them without harding the tgname..
Thanks

--
LL

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Linh Luong (#1)
Re: Diabling constraints

On Fri, 14 Sep 2001, Linh Luong wrote:

I am wondering is there any way of disabling constraints that was
created after the table itself was created.

I know I can drop the trigger that the constraint creates. However, I
need to make this change in several postgres database and it seems like
the the tgname that is required to remove the constraint is generate by
the system so I can't just go
drop trigger "<tgname>" on <tablename> because tgname is different in
all the database I need to modify.

Any ideas in disabling or removing them without harding the tgname..

Under 7.2, you should be able to use drop constraint/add constraint to
drop/re-add the constraint by its constraint name.

Under 7.1 and earlier:
If you're okay with turning off all triggers, you can do something
like:

-- Turn off
UPDATE "pg_class" SET "reltriggers" = 0 WHERE "relname" = '<tablename>';
... do stuff ...
-- Enable triggers
UPDATE pg_class SET reltriggers = (SELECT count(*) FROM pg_trigger where
pg_class.oid = tgrelid) WHERE relname = '<tablename>';

Otherwise, you could remove the triggers with a delete from pg_trigger
where the tgrelid is the table's id and the constraint name matches,
followed by the second update above to reset the trigger number.