title: postgresql: INSERT INTO ... (SELECT * ...)
body: <p>I'm not sure if its standard SQL:  </p>
  
  <pre><code> INSERT INTO tblA 
   (SELECT id, time 
      FROM tblB 
     WHERE time &gt; 1000)  
  </code></pre>
  
  <p>What I'm looking for is: <strong>what if tblA and tblB are in different DB Servers</strong>.</p>
  
  <p>Does PostgreSql gives any utility or has any functionality that will help to use <code>INSERT query with PGresult struct</code>  </p>
  
  <p>I mean <code>SELECT id, time FROM tblB ...</code> will return a <code>PGresult*</code> on using <code>PQexec</code>. Is it possible to use this struct in another <code>PQexec</code> to execute an INSERT command.  </p>
  
  <p>EDIT:<br>
  If not possible then I would go for extracting the values from PQresult* and create a multiple INSERT statement syntax like:</p>
  
  <pre><code>INSERT INTO films (code, title, did, date_prod, kind) VALUES
      ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
      ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy'); 
  </code></pre>
  
  <p>Is it possible to create a prepared statement out of this!! :(</p>