Обсуждение: BUG #6531: integrity constraint failure

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

BUG #6531: integrity constraint failure

От
claudiomsi@hotmail.com
Дата:
The following bug has been logged on the website:

Bug reference:      6531
Logged by:          Claudio Oliveira
Email address:      claudiomsi@hotmail.com
PostgreSQL version: 9.1.3
Operating system:   windows 7
Description:=20=20=20=20=20=20=20=20

Hello,

It would be a BUG.

Please run by separate blocks for the comment.

One to One Works.

By not blocks.

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

create table mestre (chave serial primary key, descricao varchar(50));

create table detalhe (chave serial primary key,=20
                      mestre integer references mestre(chave) ON DELETE
CASCADE,=20
                      valor numeric);

CREATE OR REPLACE FUNCTION ftrig_detalhe()
  RETURNS trigger AS
$BODY$
begin
 return null;
end;$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

---------------------------------------------------------------------
insert into mestre (chave, descricao) values (1, 'TESTE');
insert into detalhe (chave, mestre, valor) values (1, 1, 10);
select * from detalhe d left join mestre m on m.chave =3D d.mestre;
---------------------------------------------------------------------
delete from mestre where chave =3D 1;
select * from detalhe d left join mestre m on m.chave =3D d.mestre;
---------------------------------------------------------------------

CREATE TRIGGER tdetalhe
  before DELETE
  ON detalhe
  FOR EACH ROW
  EXECUTE PROCEDURE ftrig_detalhe();

---------------------------------------------------------------------
insert into mestre (chave, descricao) values (1, 'TESTE');
insert into detalhe (chave, mestre, valor) values (1, 1, 10);
select * from detalhe d left join mestre m on m.chave =3D d.mestre;
---------------------------------------------------------------------
delete from mestre where chave =3D 1;
select * from detalhe d left join mestre m on m.chave =3D d.mestre;
---------------------------------------------------------------------

Re: BUG #6531: integrity constraint failure

От
Tom Lane
Дата:
claudiomsi@hotmail.com writes:
> It would be a BUG.

No, this is not a bug.  If you create a trigger that disables deletions
on the referencing table, you should not be surprised that
foreign-key-related deletions don't happen.  Triggers do fire on FK
actions; it would be substantially less useful if they didn't.

            regards, tom lane