title: Inserting with subqueries using pg-promise
body: <p>I have an insert on postgres 10 that uses subqueries to look up foreign keys on a unique column, like this (just an illustration example):</p>
  
  <pre><code>CREATE TABLE company 
  (id SERIAL PRIMARY KEY, 
  name VARCHAR(50) NOT NULL,
  companyCode CHAR(4) NOT NULL UNIQUE);
  
  CREATE TABLE customer 
  (id SERIAL PRIMARY KEY,
  company NOT NULL REFERENCES company (id),
  name VARCHAR(100) NOT NULL);
  
  INSERT INTO customer (name, company) values ('Bill Gates', (select id from company where companyCode='MSFT'));
  </code></pre>
  
  <p>I'm trying to use the pg-promise NodeJS library to insert multiple rows into the database quickly.  The recommended way seems to be to use <a href="http://vitaly-t.github.io/pg-promise/helpers.html" rel="nofollow noreferrer">helpers</a>. However I haven't found anything in the documentation or the examples that refers to using subqueries in this way.</p>
  
  <p>Am I missing an obvious way to do this?  Or am I approaching the whole question in the wrong way, and is there a simpler way than pg-promise to generate the bulk insert code while still keeping the injection protection?</p>
  
  <p>Thanks! </p>