title: Postgres insert value from insert in other table
body: <p>I have two tables:</p>
  
  <pre><code>CREATE TABLE tbl_a (
  id serial primary key NOT NULL,
  name text NOT NULL,
  tbl_b_reference NOT NULL
  )
  
  CREATE TABLE tbl_b (
  id serial primary key NOT NULL,
  status text)
  </code></pre>
  
  <p>I want to do two inserts. One in tbl_b, and then use the id from that insert when I do my insert into tbl_a.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>INSERT INTO tbl_a(name, tbl_b_reference) 
  VALUES ("myName", (INSERT INTO tbl_b (status) VALUES ('OK') RETURNING id));
  </code></pre>
  
  <p>but I only get a syntax error pointing at the second "INTO"</p>
  
  <pre><code>ERROR: syntax error at or near "INTO" Position: 68
  </code></pre>
  
  <p>Where do I go from here and is it possible to do this without writing permanent functions or creating triggers? I'm new to postgres and just know some basics of MySQL/MariaDB. I've been searching around here for other questions related to nested inserts but couldn't find something that I managed to actually use, so code examples would be much appreciated.</p>