title: Postgresql referenced inserts inside triggers
body: <p>I have an issue with three tables, let call them table <strong>source</strong>, table <strong>parent</strong> and table <strong>child</strong>.</p>
  
  <p>When a row is inserted on table <strong>source</strong>, an after insert trigger is triggered, inside the function attached two main tasks are done:
  - First an insert on table <strong>parent</strong>, with the pk value taken from the <strong>source</strong>.
  - Second an insert on table <strong>child</strong>, with a reference to the <strong>parent</strong> before inserted row.</p>
  
  <p>What is happening is that a foreign_key_violation error is triggered when the second insert is tried to do.</p>
  
  <p>This error disappear if I remove the reference constraint on table <strong>child</strong>.</p>
  
  <p>But I wish to have this constraint.
  I've tried with add to this constraint <code>DEFERRABLE INITIALLY DEFERRED</code>.
  But the issue persist.</p>
  
  <p>So all works as if the first insert remains invisible to the second one,
  so the second insert can't reference the first one.</p>