PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

usando COPY FROM em um aplicativo Rails no Heroku com o backend Postgresql


Graças ao link do @PhilipHallstrom, usei COPY FROM STDIN assim:
rc = User.connection.raw_connection
rc.exec("COPY users (name, taxon_id, updated_at, created_at) FROM STDIN")
begin
  until rc.put_copy_data( data )
    $stderr.puts "  waiting for connection to be writable..."
    sleep 0.1
  end
rescue Errno => err
  @errmsg = @errmsg + "%s while reading copy data: %s" % [ err.class.name, err.message ]
  error = true
else
  rc.put_copy_end
  while res = rc.get_result
    if (res.result_status != 1)
      error = true
      @errmsg = @errmsg + "Result of COPY is: %s" % [ res.res_status(res.result_status) ]
    end
  end
end