PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Problemi con il comando COPY postgresql con Rails su server diversi

Puoi usare COPY FROM STDIN per aggirare questo... in questo modo:

conn = ActiveRecord::Base.connection_pool.checkout
raw  = conn.raw_connection
raw.exec("COPY tablename (col1, col2, col3) FROM STDIN")
# open up your CSV file looping through line by line and getting the line into a format suitable for pg's COPY...
raw.put_copy_data line
# once all done...
raw.put_copy_end
while res = raw.get_result do; end # very important to do this after a copy
ActiveRecord::Base.connection_pool.checkin(conn)

Credo che ci siano alcune opzioni per COPIA che ti permetteranno di specificare che stai passando i dati CSV, il che renderebbe tutto ancora più semplice...