Day: March 11, 2019

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();