title: Using Go to copy from one postgres db to another
body: <p>I'd like to use Go to copy postgres data from database A, view A into Database B, table B.  This will be done for several dozen tables and I'd like to take advantage of the concurrency offered by Go.  </p>
  
  <p>I can do this using psql commandline that looks something like: </p>
  
  <pre><code>psql -h hostServer -p 5432 -U dbUser -d dbName \
      -c "\copy (Select * From myView) TO STDOUT" \
      | psql -h destinationHost -p 5432 -U dbUser -d destinationDB \
      -c "\copy destinationTable FROM STDIN"
  </code></pre>
  
  <p>Or in Python by running the above command or by using os.pipe and psycpog2's copy_from/to commands.  Unfortunately, neither of these options seem to play too well with concurrency.  This is why I'm looking to do the same thing in go.</p>
  
  <p>So my question - how can I run the above command line command in GO?  Or pipe data to/from different postgres databases?  I'v been experimenting with the following code and haven't had success.  Any tips would be appreciated.</p>
  
  <pre><code>import "github.com/go-pg/pg"
  
  //connect to source and destination db's (successful connection confirmed)
  
  r, w := io.Pipe()
  
  println("start")
  
  _, err := destDB.CopyFrom(r, "COPY destinationTable FROM STDIN")
  if err != nil {
      println(err)
  }
  
  _, err = srcDB.CopyTo(w, "COPY (SELECT * FROM sourceView) TO STDOUT")
  if err != nil {
      println(err)
  }
  
  srcDB.Close()
  destDB.Close()
  </code></pre>