Post-create trigger example (PostgreSQL)

create or replace function after_deferred_entity_created_function()
  returns trigger as
$BODY$
begin
  if new.parentid isnull
  then
    update deferredentity set parentid = nextval('entity_id_seq') where id = new.id;
  end if;

  return NEW;
end;
$BODY$
  language plpgsql;

create trigger after_deferred_entity_created_trigger
  after insert
  on deferredentity
  for each row
execute procedure after_deferred_entity_created_function();

Leave a Reply

Your email address will not be published. Required fields are marked *