I've got a postgres DB with around 200,000,000 rows and 6 columns. The columns have int, date, and string, but no primary key and no unique values on which to base a primary key.
The records in this DB contain the raw data I need for one of my rails postgres models. I'd like to iterate through the full external DB, perform a calculation on each row of it, and then write the output to my rails model.
I've got no issue connecting to the DB or accessing records through ActiveRecord, but everything I try for iterating over the DB is failing or taking far too long. I've tried the following:
- ExternalDB.all.each
- ExternalDB.find_all.each
- Adding an "id" column to ExternalDB using these instructions
I think the answer will be to do the iterations using SQL, but I'm not even sure how to start on that.