Thread: what wrong????

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    jakarta
    Posts
    11
    Rep Power
    0

    Angry Creating Trigger for loging table


    Iam trying to make a trigger for backup table. When a delete operation for table1, it will copy deleted data to table2.

    table1:
    create table1 (id int4, name text);

    table2:
    create table2 (id int4, name text);

    function execute by trigger:
    create function backup_func() returns OPAQUE as '
    begin
    insert into tabel2(id, nama) values (OLD.id, OLD.nama);
    end;
    ' language 'plpgsql';

    trigger for table1:
    create trigger mytrigger after delete on tabel1 for each row execute procedure backup_func();

    then insert some data:
    insert into table1 (id, name) values (1, 'Mao Tze Dong');
    insert into table1 (id, name) values (2, 'Hitler');

    All above operations are doing fine. but when deleting data in table1 an error occor:

    delete from table1 where id = 2;

    ERROR: control reaches end of trigger procedure without RETURN

    please help.. how to make a trigger for a table so that when the table do delete operation it can backup into anoter table?

    thanks
    Last edited by bambanghendra; August 22nd, 2001 at 02:35 AM.
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    30
    I have never written a trigger in Postgresql. The documentation says:
    "...they must return either NULL or a record/row containing exactly the structure of the table the trigger was fired for."

    Based on your error message and the documentation above, would adding a RETURN NULL; before the end; statement solve your problem? Postgresql does not appear to like that your trigger doesn't have a return value.

    This is just a guess.

    http://www.postgresql.org/idocs/inde...l-trigger.html
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    jakarta
    Posts
    11
    Rep Power
    0
    Thanks dcaillouet

    Postgresql does not appear to like that your trigger doesn't have a return value.
    Yes... a function shoud have a return value

    But RETURN OLD or RETURN NEW will be fine.

IMN logo majestic logo threadwatch logo seochat tools logo