Search code examples
sqlpostgresqltriggersddlddl-trigger

in postgresql, is ti possible to create triggers to a table with triggers on CREATE TABLE?


is is possible in postgres to have a trigger on CREATE TABLE that will create triggers for the newly created table?

for example,

CREATE TABLE base_abc(
   ...
) inherits( base );

I would like to automatically add triggers to the newly create table base_abc that would, for example, that would calculate a column value based on column names.

likewise, is it possible to trigger on ALTER TABLE so that the triggers can be dropped and recreated?

for context, see what is best way to extend postgresql to index json objects?


Solution

  • Don't think there's a way to implement such "triggers" using PostgreSQL built-in functions, but you can definitely write a stored function that will do what you want - i.e. create a derived table and then a trigger on that table.

    You can also write one for ALTERing tables.