2

Hi I have data in a csv file format that Id like to import into my postgresql. The postgresql would be used in my rails app as a prepopulated db. I realize rails uses a ORM . So I was wondering if its good to import data into the db like this.

If not how should I do it?

2 Answers 2

3

In general, for bulk loading you'll want to use the COPY interface or, if you can afford downtime and have truly monsterous amounts of data to load, pg_bulkload.

COPY can be client- or server-side. For client-side COPY your client needs to support it. libpq does, as does the psql client. PgJDBC also supports COPY from client side. I don't know if Ruby's database interface does, but I doubt it. If it doesn't you can use server-side COPY if you have appropriate access permissions on the server, or you can shell out to psql to do the bulk import using the psql \copy command.

Sign up to request clarification or add additional context in comments.

1 Comment

You can bulk load from the Ruby side via the native database connection (that ActiveRecord uses under the covers). It works quite well, but is more fiddly than using AR.
0

Your question is largely answered by the sample code in this question - Ignore first line on csv parse Rails

I don't have the power to flag this question as a duplicate however.

1 Comment

Yes but that post is using a gem to parse csv. I was wondering if I can use a migration tool to accomplish this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.