title: How to return id after insert from updated (created from trigger) table in postgres?
body: <p>I am creating an insert query to a table (t1 -Which creates the returning id by increment) which adds the same row to another table (t2) by a trigger and creates a new id. How do I get this new ID? </p>
  
  <p>I tried the following approach but it returns null (I think the row in table t2 is not available yet to perform join on).</p>
  
  <p>In t2 I have an identifier 'type' which detects the type of row through trigger</p>
  
  <p>Any help would be appreciated. Thanks in advance.</p>
  
  <pre><code>WITH inserted AS (
                  INSERT INTO t1 (entity_name, entity_type, entity_country)
              VALUES
                  ('sss', 'list', 'a',)
              RETURNING id, entity_country
  
      )
  
  select id, entity_reference_id, entity_country, t2.entity_id from inserted
      join t2 on t1.id = t2.entity_reference_id
  where t2.type LIKE '%manual%'
  
  </code></pre>
  
  <p>This returns me null, However I want it to return me new t2.entity_id</p>