Обсуждение: disable constraints

Поиск
Список
Период
Сортировка

disable constraints

От
rute solipa
Дата:
hello,

does anyone nows how can i disable/enable table or column constraints?

in oracle it's possible to disable constraints like this:

alter table tb_1
disable primary key;

best regards,
rute



Re: disable constraints

От
Patrik Kudo
Дата:
Hi!

use "alter table ??? drop constraint ???"

example:

create table asdf (userid text, foreign key (userid) references 
person(userid) on delete cascade);

\d asdf    Table "public.asdf" Column | Type | Modifiers
--------+------+----------- userid | text |
Foreign Key constraints: $1 FOREIGN KEY (userid) REFERENCES 
person(userid) ON UPDATE NO ACTION ON DELETE CASCADE

alter table asdf drop constraint "$1";

Regards,
Patrik Kudo

rute solipa wrote:
> hello,
> 
> does anyone nows how can i disable/enable table or column constraints?
> 
> in oracle it's possible to disable constraints like this:
> 
> alter table tb_1
> disable primary key;
> 
> best regards,
> rute
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly




Re: disable constraints

От
rute solipa
Дата:
i whant avoid to dropping constraint, i whant to disable the constraints, 
because i need to insert a large amont of data.
is there a way?

best regards,
rute



At 03:47 PM 2/26/2003 +0100, you wrote:
>Hi!
>
>use "alter table ??? drop constraint ???"
>
>example:
>
>create table asdf (userid text, foreign key (userid) references 
>person(userid) on delete cascade);
>
>\d asdf
>     Table "public.asdf"
>  Column | Type | Modifiers
>--------+------+-----------
>  userid | text |
>Foreign Key constraints: $1 FOREIGN KEY (userid) REFERENCES person(userid) 
>ON UPDATE NO ACTION ON DELETE CASCADE
>
>alter table asdf drop constraint "$1";
>
>Regards,
>Patrik Kudo
>
>rute solipa wrote:
>>hello,
>>does anyone nows how can i disable/enable table or column constraints?
>>in oracle it's possible to disable constraints like this:
>>alter table tb_1
>>disable primary key;
>>best regards,
>>rute
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 3: if posting/reading through Usenet, please send an appropriate
>>subscribe-nomail command to majordomo@postgresql.org so that your
>>message can get through to the mailing list cleanly
>



Re: disable constraints

От
Dmitry Tkach
Дата:
rute solipa wrote:
> i whant avoid to dropping constraint, i whant to disable the constraints, 
> because i need to insert a large amont of data.
> is there a way?
> 
> best regards,
> rute
> 
> 

There is no "oficial" way to do that, as far as I know...
You can disable *triggers* on a table (which will disable all the FK constraints, but not things like 'not nul' or
'unique'),by doing:
 

update pg_class set reltriggers=0 where relname = 'YOUR_TABLE_NAME';

to enable them after you are done, do

update pg_class set reltriggers = count(*) from pg_trigger where pg_class.oid=tgrelid and relname='YOUR_TABLE_NAME';

I hope, it helps...

Dima


> 
> At 03:47 PM 2/26/2003 +0100, you wrote:
> 
>>Hi!
>>
>>use "alter table ??? drop constraint ???"
>>
>>example:
>>
>>create table asdf (userid text, foreign key (userid) references 
>>person(userid) on delete cascade);
>>
>>\d asdf
>>    Table "public.asdf"
>> Column | Type | Modifiers
>>--------+------+-----------
>> userid | text |
>>Foreign Key constraints: $1 FOREIGN KEY (userid) REFERENCES person(userid) 
>>ON UPDATE NO ACTION ON DELETE CASCADE
>>
>>alter table asdf drop constraint "$1";
>>
>>Regards,
>>Patrik Kudo
>>
>>rute solipa wrote:
>>
>>>hello,
>>>does anyone nows how can i disable/enable table or column constraints?
>>>in oracle it's possible to disable constraints like this:
>>>alter table tb_1
>>>disable primary key;
>>>best regards,
>>>rute
>>>
>>>---------------------------(end of broadcast)---------------------------
>>>TIP 3: if posting/reading through Usenet, please send an appropriate
>>>subscribe-nomail command to majordomo@postgresql.org so that your
>>>message can get through to the mailing list cleanly
>>
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org



Re: disable constraints

От
Bruce Momjian
Дата:
TODO has:
* Allow triggers to be disabled [trigger]

and referential constraints are implemented using triggers, so no, we
don't have that functionality yet.

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

rute solipa wrote:
> i whant avoid to dropping constraint, i whant to disable the constraints, 
> because i need to insert a large amont of data.
> is there a way?
> 
> best regards,
> rute
> 
> 
> 
> At 03:47 PM 2/26/2003 +0100, you wrote:
> >Hi!
> >
> >use "alter table ??? drop constraint ???"
> >
> >example:
> >
> >create table asdf (userid text, foreign key (userid) references 
> >person(userid) on delete cascade);
> >
> >\d asdf
> >     Table "public.asdf"
> >  Column | Type | Modifiers
> >--------+------+-----------
> >  userid | text |
> >Foreign Key constraints: $1 FOREIGN KEY (userid) REFERENCES person(userid) 
> >ON UPDATE NO ACTION ON DELETE CASCADE
> >
> >alter table asdf drop constraint "$1";
> >
> >Regards,
> >Patrik Kudo
> >
> >rute solipa wrote:
> >>hello,
> >>does anyone nows how can i disable/enable table or column constraints?
> >>in oracle it's possible to disable constraints like this:
> >>alter table tb_1
> >>disable primary key;
> >>best regards,
> >>rute
> >>
> >>---------------------------(end of broadcast)---------------------------
> >>TIP 3: if posting/reading through Usenet, please send an appropriate
> >>subscribe-nomail command to majordomo@postgresql.org so that your
> >>message can get through to the mailing list cleanly
> >
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org
> 

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073