Missing/Empty? import/postgresql.rb
-
Zach Dennis
Hi James,
I know this hasn't been implemented as I don't use PostgreSQL, but I am surprised by the error. It should fall back one insert per row. I'll look into this.
-
James B. Byrne
Maybe it is something that I am doing wrong in my call. I back dated to 0.8.2 and get the same result.
I am trying to do this within an ActiverRecord model so perhaps that is the problem. The entire code looks like this:
class CurrencyExchangeRate < ActiveRecord::Base # This is a class method not an instance. def self.load(rates,date=false) # date can be nil, false, true or a date date = Time.now.strftime("%Y-%m-%d") unless date # not nil or false date = date unless date == true # not a date # otherwise we use the individual dates passed in the array # Now, require ar-extensions for mass update require 'ar-extensions/adapters/postgresql' require 'ar-extensions/import/postgresql' # Now, set the number of rates to update per batch batch_size = 100 # Now, define the row update array new_rates = Array.new # could use [] but this is clearer rates.each do |rate| # rate is a hash new_rates << CurrencyExchangeRate.new(rate) if new_rates.size % batch_size == 0 # if we have exactly batch_size CurrencyExchangeRate.import new_rates, :validate => validate new_rates = [] # empty the rates array end end if new_rates.size > 0 # load last batch regardless of size CurrencyExchangeRate.import new_rates, :validate => validate end puts 'forex loader end' end
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.