Thread: trigger inheritance

trigger inheritance

From
"Horst Herb"
Date:
In Postgres, is it possible to write a (trigger) function for a table "parent" that is inherited automatically by
tables"children" ? 

If so, how?

And how would this trigger function access _all_ columns in the table "children"?

Example:

create table parent (
    id serial,
    crc32 int4
);

create function calculate_crc()
returns opaque
as 'BEGIN
    new.crc32 = my_external_crc_func();
    -- my_external_crc_func must be able to "see" all columns of "new"
END;'
language 'plpgsql';

CREATE TRIGGER inherited
BEFORE INSERT OR UPDATE
ON parent
FOR EACH ROW
EXECUTE PROCEDURE calculate_crc();


create table child (
    something text
) inherits (parent);


When I try this, "child" does not seem to inherit the trigger. What's more - I don't know how to let
"my_external_crc_func"(loaded dynamically) can "see" all columns in "child". 

Who can help me?

Most thankful for any hints,
Horst