Temparary disable constraint

Started by Hubert FONGARNANDalmost 19 years ago9 messages
#1Hubert FONGARNAND
informatique.internet@fiducial.fr

Hi,

Is there a way to temporary disable a constraint (without drop and
recreating it) in postgresql?

Thanks
_______________________________________________
Ce message et les �ventuels documents joints peuvent contenir des informations confidentielles.
Au cas o� il ne vous serait pas destin�, nous vous remercions de bien vouloir le supprimer et en aviser imm�diatement l'exp�diteur. Toute utilisation de ce message non conforme � sa destination, toute diffusion ou publication, totale ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'�tant pas s�curis�es, l'int�grit� de ce message n'est pas assur�e et la soci�t� �mettrice ne peut �tre tenue pour responsable de son contenu.

#2Bruce Momjian
bruce@momjian.us
In reply to: Hubert FONGARNAND (#1)
Re: Temparary disable constraint

Hubert FONGARNAND wrote:

Hi,

Is there a way to temporary disable a constraint (without drop and
recreating it) in postgresql?

Sure, try ALTER TABLE ... DISABLE TRIGGER for the constraint trigger
name.

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#3Hubert FONGARNAND
informatique.internet@fiducial.fr
In reply to: Bruce Momjian (#2)
Re: Temparary disable constraint

Ok it works, but we have to write a plpgsql function that takes the
table_name and the constraint name in parameters....

It could be useful to have a : ALTER TABLE ... DISABLE CONSTRAINT ...
(as oracle does)

it could be good to add this to the TODO LIST...

Thanks

Le mardi 16 janvier 2007 à 22:02 -0500, Bruce Momjian a écrit :

Hubert FONGARNAND wrote:

Hi,

Is there a way to temporary disable a constraint (without drop and
recreating it) in postgresql?

Sure, try ALTER TABLE ... DISABLE TRIGGER for the constraint trigger
name.

_______________________________________________
Ce message et les �ventuels documents joints peuvent contenir des informations confidentielles.
Au cas o� il ne vous serait pas destin�, nous vous remercions de bien vouloir le supprimer et en aviser imm�diatement l'exp�diteur. Toute utilisation de ce message non conforme � sa destination, toute diffusion ou publication, totale ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'�tant pas s�curis�es, l'int�grit� de ce message n'est pas assur�e et la soci�t� �mettrice ne peut �tre tenue pour responsable de son contenu.

#4Adnan DURSUN
a_dursun@hotmail.com
In reply to: Bruce Momjian (#2)
Re: Temparary disable constraint

Hi,
Maybe added more further things to TODO list. Enabled / disabled other objects like view/funtion. imagine a lot of views that referances a table and i wanna drop a column on this table that used by these views. Postgres doesnt allow this. First i must drop these views then drop the column on that table and then recreate these views.
Can this be resolved (like oracle does) ?

Best regards

Adnan DURSUN
ASRIN Bilişim Ltd.
----- Original Message -----
From: Hubert FONGARNAND
To: Bruce Momjian
Cc: pgsql-hackers@postgresql.org
Sent: Wednesday, January 17, 2007 10:36 AM
Subject: Re: [HACKERS] Temparary disable constraint

Ok it works, but we have to write a plpgsql function that takes the table_name and the constraint name in parameters....

It could be useful to have a : ALTER TABLE ... DISABLE CONSTRAINT ...
(as oracle does)

it could be good to add this to the TODO LIST...

Thanks

Le mardi 16 janvier 2007 à 22:02 -0500, Bruce Momjian a écrit :
Hubert FONGARNAND wrote:

Hi,

Is there a way to temporary disable a constraint (without drop and
recreating it) in postgresql?

Sure, try ALTER TABLE ... DISABLE TRIGGER for the constraint trigger
name.

_______________________________________________
Ce message et les 鶥ntuels documents joints peuvent contenir des informations confidentielles.
Au cas o?ne vous serait pas destin鬠nous vous remercions de bien vouloir le supprimer et en aviser imm餩atement l'exp餩teur. Toute utilisation de ce message non conforme ࠳a destination, toute diffusion ou publication, totale ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'鴡nt pas s飵ris饳, l'int駲it頤e ce message n'est pas assur饠et la soci鴩 魥ttrice ne peut 괲e tenue pour responsable de son contenu.

#5Bruce Momjian
bruce@momjian.us
In reply to: Hubert FONGARNAND (#3)
Re: Temparary disable constraint

Hubert FONGARNAND wrote:

Ok it works, but we have to write a plpgsql function that takes the
table_name and the constraint name in parameters....

It could be useful to have a : ALTER TABLE ... DISABLE CONSTRAINT ...
(as oracle does)

it could be good to add this to the TODO LIST...

Well, we currently only allow disabling foreign key constraints (those
that have triggers). There is no way to disable a UNIQUE or NOT NULL
constraint, for example, so I don't see how we can do DISABLE CONSTRAINT
cleanly.

---------------------------------------------------------------------------

Thanks

Le mardi 16 janvier 2007 ? 22:02 -0500, Bruce Momjian a ?crit :

Hubert FONGARNAND wrote:

Hi,

Is there a way to temporary disable a constraint (without drop and
recreating it) in postgresql?

Sure, try ALTER TABLE ... DISABLE TRIGGER for the constraint trigger
name.

_______________________________________________
Ce message et les ?entuels documents joints peuvent contenir des informations confidentielles.
Au cas o?il ne vous serait pas destin? nous vous remercions de bien vouloir le supprimer et en aviser imm?iatement l'exp?iteur. Toute utilisation de ce message non conforme ?sa destination, toute diffusion ou publication, totale ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'?ant pas s?uris?s, l'int?rit?de ce message n'est pas assur? et la soci???ettrice ne peut ?re tenue pour responsable de son contenu.

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#6Bruce Momjian
bruce@momjian.us
In reply to: Adnan DURSUN (#4)
Re: Temparary disable constraint

Adnan DURSUN wrote:

Hi, Maybe added more further things to TODO list. Enabled /
disabled other objects like view/funtion. imagine a lot of
views that referances a table and i wanna drop a column on this
table that used by these views. Postgres doesnt allow this.
First i must drop these views then drop the column on that
table and then recreate these views. Can this be resolved
(like oracle does) ?

Not easily, because the view are bound to the object id of the tables
involved.

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#7Adnan DURSUN
a_dursun@hotmail.com
In reply to: Bruce Momjian (#6)
Re: Temparary disable constraint

Maybe you are right as technically but this behaver causes a lot
of maintance problem on a database that alot of view and functions that
depends on a table or a type. I think objects has a property if that object
is enable or not. We hope this problem can be resolved at 8.4 release.

Best Regards

Adnan DURSUN
ASRIN Bilisim Ltd.

----- Original Message -----
From: "Bruce Momjian" <bruce@momjian.us>
To: "Adnan DURSUN" <a_dursun@hotmail.com>
Cc: <pgsql-hackers@postgresql.org>
Sent: Wednesday, January 17, 2007 5:49 PM
Subject: Re: [HACKERS] Temparary disable constraint

Show quoted text

Adnan DURSUN wrote:

Hi, Maybe added more further things to TODO list. Enabled /
disabled other objects like view/funtion. imagine a lot of
views that referances a table and i wanna drop a column on this
table that used by these views. Postgres doesnt allow this.
First i must drop these views then drop the column on that
table and then recreate these views. Can this be resolved
(like oracle does) ?

Not easily, because the view are bound to the object id of the tables
involved.

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

#8Richard Huxton
dev@archonet.com
In reply to: Bruce Momjian (#6)
Re: Temparary disable constraint

Bruce Momjian wrote:

Adnan DURSUN wrote:

Hi, Maybe added more further things to TODO list. Enabled /
disabled other objects like view/funtion. imagine a lot of
views that referances a table and i wanna drop a column on this
table that used by these views. Postgres doesnt allow this.
First i must drop these views then drop the column on that
table and then recreate these views. Can this be resolved
(like oracle does) ?

Not easily, because the view are bound to the object id of the tables
involved.

The trick would be I think to bind them to individual columns, so if
view V doesn't mention column C then dropping C has no effect on it.

That's a lot more dependencies to track of course.

--
Richard Huxton
Archonet Ltd

#9Adnan DURSUN
a_dursun@hotmail.com
In reply to: Bruce Momjian (#6)
Re: Temparary disable constraint

----- Original Message -----
From: "Richard Huxton" <dev@archonet.com>
To: "Bruce Momjian" <bruce@momjian.us>
Cc: "Adnan DURSUN" <a_dursun@hotmail.com>; <pgsql-hackers@postgresql.org>
Sent: Thursday, January 18, 2007 5:57 PM
Subject: Re: [HACKERS] Temparary disable constraint

Not easily, because the view are bound to the object id of the tables
involved.

The trick would be I think to bind them to individual columns, so if view
V doesn't mention column C then dropping C has no effect on it.

That's a lot more dependencies to track of course.

Is that not possible that all objects have a column that says whether
object state is ok or not.
When any session wants to try to execute any DML on object, then the
Postgres checks that state column.
If object state is not ok then Postgres raises an exception.

Best Regards

Adnan DURSUN
ASRIN Bilisim Ltd.