How to replace rows in table so that foreign key rows are not deleted

Поиск
Список
Период
Сортировка
От Andrus
Тема How to replace rows in table so that foreign key rows are not deleted
Дата
Msg-id e287fo$1v2m$1@news.hub.org
обсуждение исходный текст
Ответы Re: How to replace rows in table so that foreign key rows  (Berend Tober <btober@seaworthysys.com>)
Re: How to replace rows in table so that foreign key rows  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-general
I want to replace ( delete and insert) records in master table .
I delete and insert record with same primary key.
I want that foreign key records are not deleted.

I tried

begin;
create temp table t1 ( pk integer primary key );
insert into t1 values(1);
create temp table t2 (fk integer );
alter table t2 add foreign key (fk) references t1 on delete cascade
deferrable initially deferred;
insert into t2 values(1);
-- Howto: set delete_constraint deferred
delete from t1;
insert into t1 values(1);
commit;
select * from t2;

Observed: no rows

Expected: t2 must contain one row.

foreign key check and deletion should occur only when transaction commits.

Any idea ?
Is there any generic way to turn off foreign key constraints before delete
command in transaction ?

Andrus.



В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: FW: code to cancel a running query, worker thread
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: HUGE Stack space is gettiing consumed