Thread: no OID field in OLD or NEW records inside trigger functions?

no OID field in OLD or NEW records inside trigger functions?

From
Louis-David Mitterrand
Date:
This trigger function attempts to copy a record into an archive table
before deletion:

    create trigger archive_adresse before update or delete on adresse
        for each row execute procedure archive_row();

    create function archive_row() returns opaque as '
    DECLARE
        tname text;
        rec RECORD;
    BEGIN
        tname := TG_RELNAME || ''_archive'';
        INSERT INTO tname SELECT * from TG_RELNAME WHERE oid = OLD.oid;
        RETURN OLD;
    END;
    ' language 'plpgsql';

But I get:
psql:archive.sql:25: ERROR:  record old has no field oid

What would the best way to have a generic trigger function copy an
entire NEW or OLD row to an archive (given that the archive table is
always named <table>_archive)?

Thanks in advance,

--
"2c98611832ea3f6f5fdda95d3704fbb8" (a truly random sig)