Forum: Ruby on Rails How should I do update?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0ce4db5e1083663c575158643313852c?d=identicon&s=25 pedz (Guest)
on 2007-05-22 05:17
(Received via mailing list)
I have a record called a PMR.  Each PMR has a number of Signatures.
Each Signature has a number of Lines.

Currently I have a routine that is feed an entire PMR as a file and it
parses it into the proper structure and stores it.

The problem is that the PMR gross over time.  I am receiving it from
another application.  The easiest way to get it is to just get the
whole thing.

I can re-parse the whole thing and create the internal Ruby
structures.  That process is pretty fast.  But then what?  Should I
fetch the old and compare record by record and update only what
changes?  Or I could delete the old and save the new.

Any suggestions?

6e9db38e16957cc51cf9cee9de399249?d=identicon&s=25 dasil003 (Guest)
on 2007-05-22 05:26
(Received via mailing list)
If you're using MySQL look into ON DUPLICATE KEY UPDATE syntax which
will allow you to do a massive insert without clobbering existing rows
and instead update them how you see fit.  To use it with ActiveRecord
you will need to install ActiveRecord::Extensions by Zach Dennis.
0ce4db5e1083663c575158643313852c?d=identicon&s=25 pedz (Guest)
on 2007-05-22 05:36
(Received via mailing list)
Thanks.  I'm using postgreSQL.  Your suggestion got me to searching
though.  I could push the "work" down into the database.  But, then I
thought about it longer and it would only postpone the question:
delete or update.

PostgreSQL has Rules which one person used to implement ON DUPLICATE
6e9db38e16957cc51cf9cee9de399249?d=identicon&s=25 dasil003 (Guest)
on 2007-05-22 05:58
(Received via mailing list)
Well only you can answer that question.  I've used both approaches,
but the ON DUPLICATE KEY UPDATE advantage is an orders of magnitude
increase in speed for the update situation.  But if you can get away
with truncating the table and just re-inserting, that is generally the
easier thing to do.  I would still look at arextensions just for the
mass INSERT which offers a huge performance improvement when you are
importing thousands of rows.
0ce4db5e1083663c575158643313852c?d=identicon&s=25 pedz (Guest)
on 2007-05-22 06:08
(Received via mailing list)

It is probably better to do it in the DB somehow.  The less data that
passes from the DB to Rails and back, the better.

So, I'll dig into the Rules stuff and see if I can figure it out.

Thanks again.
This topic is locked and can not be replied to.