Problems with postgresql COPY command with Rails on different server -
i have rails app has been working months. in few places call directly database via activerecord::base.connection.execute( sql_code )
with recent need scale, added second server data processing. want run same app connect on network other database server. difference here. other areas of app work--it can connect remote database.
where breaking, have rails issue psql copy command import csv file.
result = activerecord::base.connection.execute( @pgsql_copy_command ) # perform copy command
this fails , says csv file can not found. have verified there , readable both user running rails app , postgres user.
am missing something?
you can use copy stdin around this... so:
conn = activerecord::base.connection_pool.checkout raw = conn.raw_connection raw.exec("copy tablename (col1, col2, col3) stdin") # open csv file looping through line line , getting line format suitable pg's copy... raw.put_copy_data line # once done... raw.put_copy_end while res = raw.get_result do; end # important after copy activerecord::base.connection_pool.checkin(conn)
i believe there options copy let specify you're passing in csv data make easier...
Comments
Post a Comment