I need to log table "foo" real deletes.
"foo" has foreign key relation established but no data exists.
Postgres 8.1 calls "foo" delete trigger when record is deleted from master
table "klient". Why ?
How to modify the following code so that record is inserted into serveri
table only when records are really deleted from foo table ?
Is it possible to add some check into trigger code?
CREATE TABLE serverti ( notice char(50));
CREATE FUNCTION setlastchange() RETURNS "trigger" AS $$
BEGIN
INSERT INTO serverti values ('changed');
RETURN NULL;
END$$ LANGUAGE plpgsql;
CREATE table klient ( kood integer primary key );
CREATE TABLE foo (
klient char(12) NOT NULL,
toode char(20) NOT NULL,
CONSTRAINT foo_pkey PRIMARY KEY (klient, toode),
CONSTRAINT foo_klient_fkey FOREIGN KEY (klient)
REFERENCES klient (kood) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE
) ;
CREATE TRIGGER foo_trig
BEFORE INSERT OR UPDATE OR DELETE ON foo
FOR EACH STATEMENT
EXECUTE PROCEDURE setlastchange();
insert into klient values (1);
-- Next line causes execution of foo_trig. Why ?
delete from klient where kood=1;
Andrus.