ruby on rails - Insert an element into a PostgreSQL array without overwriting it -


i want insert data array column in postgres.

sample_model = mymodel.create 100.times   sample_model.array.push [time.now.to_i, 1234]   sample_model.save   end 

this takes 0.5 seconds complete , inefficient. code overwrites array every time. same code using mongodb , mongoid takes 0.08 seconds complete.

sample_model = mymongoidmodel.create 100.times   sample_model.push(array: [[time.now.to_i, 1234]])  end 

is there way insert element postgres array column mongo does? i'll consider pure sql solutions.

sql solution:

class mymodel < activerecord::base   has_many :time_entries, dependent: :destroy, inverse_of: :my_model end  class timeentry < activerecord::base   belongs_to :my_model, inverse_of :time_entries   validates_presence_of: time end  100.times {mymodel.last.time_entries.create(time: time.now)} 

Comments