<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Efficient Updates &amp; Data Import in Rails</title>
	<atom:link href="http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/</link>
	<description>A goal is a dream with a deadline.</description>
	<pubDate>Thu, 18 Mar 2010 04:43:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Edgar S</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-226242</link>
		<dc:creator>Edgar S</dc:creator>
		<pubDate>Wed, 16 Dec 2009 19:47:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-226242</guid>
		<description>Hey I'm trying to use this method instead of modifying the "set multiple statements on" of MySQL client to true, but I'm having some trouble it seems the options (:on_duplicate_key_update) is not being picked up by the ar_ext, so I always get the duplicate key error from mySQL, any Ideas? what I need is a massive update of records, could be several thousands. Thanks in advanced.</description>
		<content:encoded><![CDATA[<p>Hey I&#8217;m trying to use this method instead of modifying the &#8220;set multiple statements on&#8221; of MySQL client to true, but I&#8217;m having some trouble it seems the options (:on_duplicate_key_update) is not being picked up by the ar_ext, so I always get the duplicate key error from mySQL, any Ideas? what I need is a massive update of records, could be several thousands. Thanks in advanced.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-192534</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Sun, 10 May 2009 14:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-192534</guid>
		<description>Matthew, unfortunately I'm not aware of any function in MySQL which will give you that. One workaround I've seen people do when they needed this functionality is to keep an external counter for ID's, increment it by required amount prior to insert and then insert the records with the ID values preset in the data - that way, you know what range your records occupy. It's a little messy, but it works.</description>
		<content:encoded><![CDATA[<p>Matthew, unfortunately I&#8217;m not aware of any function in MySQL which will give you that. One workaround I&#8217;ve seen people do when they needed this functionality is to keep an external counter for ID&#8217;s, increment it by required amount prior to insert and then insert the records with the ID values preset in the data - that way, you know what range your records occupy. It&#8217;s a little messy, but it works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-192244</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 08 May 2009 23:12:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-192244</guid>
		<description>Thanks for the great article. A few people had posted about multi-row inserts that need id's to join. When doing a Widget.import widgets, is there a way to get a list of the insert'ed id's the mysql equivalent of last_insert_id for multi row insets?</description>
		<content:encoded><![CDATA[<p>Thanks for the great article. A few people had posted about multi-row inserts that need id&#8217;s to join. When doing a Widget.import widgets, is there a way to get a list of the insert&#8217;ed id&#8217;s the mysql equivalent of last_insert_id for multi row insets?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#8230; So We Built One :: ActiveRecord::Base.connection.execute(&#8230; multiple statements against a mysql db &#8230;)</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-149175</link>
		<dc:creator>&#8230; So We Built One :: ActiveRecord::Base.connection.execute(&#8230; multiple statements against a mysql db &#8230;)</dc:creator>
		<pubDate>Wed, 26 Nov 2008 06:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-149175</guid>
		<description>[...] almost all cases it would be better to use ar-extensions with the duplicate key error update trick. Some colleagues of mine, who invented a plugin to invalidate find_by_sql unless you provide an [...]</description>
		<content:encoded><![CDATA[<p>[...] almost all cases it would be better to use ar-extensions with the duplicate key error update trick. Some colleagues of mine, who invented a plugin to invalidate find_by_sql unless you provide an [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Methot</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-101101</link>
		<dc:creator>Eric Methot</dc:creator>
		<pubDate>Sun, 20 Jan 2008 11:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-101101</guid>
		<description>Hi Ilya, I would really be interested in the results you get on real prod code whenever you get around to it. Thanks in advance, Eric</description>
		<content:encoded><![CDATA[<p>Hi Ilya, I would really be interested in the results you get on real prod code whenever you get around to it. Thanks in advance, Eric</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-100992</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Sat, 12 Jan 2008 19:09:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-100992</guid>
		<description>Michael, believe it or not, that should be it. The steps are: establish connection to database, load your items, import your items. After you execute Item.import, check your database -- all of your records should be residing in there!

Eric, very interesting extension to ActiveRecord. I did a quick pass over your code and it's a pretty neat, Ruby idiom specific, implementation. I'll make sure to test-drive it with some production code in the future.</description>
		<content:encoded><![CDATA[<p>Michael, believe it or not, that should be it. The steps are: establish connection to database, load your items, import your items. After you execute Item.import, check your database &#8212; all of your records should be residing in there!</p>
<p>Eric, very interesting extension to ActiveRecord. I did a quick pass over your code and it&#8217;s a pretty neat, Ruby idiom specific, implementation. I&#8217;ll make sure to test-drive it with some production code in the future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Methot</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-100977</link>
		<dc:creator>Eric Methot</dc:creator>
		<pubDate>Sat, 12 Jan 2008 09:40:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-100977</guid>
		<description>I put together a small plugin (&lt;a href="http://railsparhasard.ericmethot.com/journal/2008/1/9/multi-statement-query-plugin.html" title="multi-statement-query rails plugin" rel="nofollow"&gt;multi-statement-query&lt;/a&gt;) that allows AR to take advantage of MySQL's ability to handle such queries (with some limitations of course). It could be used as a complement to Zack's extension allowing you to also do selects, updates and other insert statements in one go. I mention it here because this is one of the sites that I have stumbled upon when researching the plugin. 

Cheers</description>
		<content:encoded><![CDATA[<p>I put together a small plugin (<a href="http://railsparhasard.ericmethot.com/journal/2008/1/9/multi-statement-query-plugin.html" title="multi-statement-query rails plugin" rel="nofollow">multi-statement-query</a>) that allows AR to take advantage of MySQL&#8217;s ability to handle such queries (with some limitations of course). It could be used as a complement to Zack&#8217;s extension allowing you to also do selects, updates and other insert statements in one go. I mention it here because this is one of the sites that I have stumbled upon when researching the plugin. </p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Staton</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-100945</link>
		<dc:creator>Michael Staton</dc:creator>
		<pubDate>Thu, 10 Jan 2008 00:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-100945</guid>
		<description>Ilya, this all makes sense except for the steps left out for the noobs....  Where do I put this code?  How do I execute it?  

I got a huge file that goes, for example, 
items = [Item.new(data hash), etc. ]
Item.import items

Now what?</description>
		<content:encoded><![CDATA[<p>Ilya, this all makes sense except for the steps left out for the noobs&#8230;.  Where do I put this code?  How do I execute it?  </p>
<p>I got a huge file that goes, for example,<br />
items = [Item.new(data hash), etc. ]<br />
Item.import items</p>
<p>Now what?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-85683</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Tue, 13 Nov 2007 07:43:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-85683</guid>
		<description>Marc, unfortunately your example will require some manual 'muck'. There is no direct way (that I'm aware of), to do a multi-value habtm import aside from running two separate multi-value imports. 

As long as you know the correct mappings between ID's, I would first load the parent table, and then import the children  as a separate query.</description>
		<content:encoded><![CDATA[<p>Marc, unfortunately your example will require some manual &#8216;muck&#8217;. There is no direct way (that I&#8217;m aware of), to do a multi-value habtm import aside from running two separate multi-value imports. </p>
<p>As long as you know the correct mappings between ID&#8217;s, I would first load the parent table, and then import the children  as a separate query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Busch</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/comment-page-1/#comment-85135</link>
		<dc:creator>Marc Busch</dc:creator>
		<pubDate>Mon, 12 Nov 2007 10:57:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-85135</guid>
		<description>Ilya, nice article. But I have a problem to understand how this can be used with habtm tables, i.e. two tables that are linked with a join table.

Example: 
Parent and Child have a has_and_belongs_to_many relation. How can I utilize ar-extension's import functionality for something like this:

1000.times {
    parent.children.create(:par0 =&gt; "test0", :par1 =&gt; "test1")
}

For every single 'create' there are two(!) INSERTs in the database, one to 'child' and the other to the join table 'chidren_parents'. If I use 'import' as described in your article, the join table will not get updated, right?

Can this be solved somehow?</description>
		<content:encoded><![CDATA[<p>Ilya, nice article. But I have a problem to understand how this can be used with habtm tables, i.e. two tables that are linked with a join table.</p>
<p>Example:<br />
Parent and Child have a has_and_belongs_to_many relation. How can I utilize ar-extension&#8217;s import functionality for something like this:</p>
<p>1000.times {<br />
    parent.children.create(:par0 =&gt; &#8220;test0&#8243;, :par1 =&gt; &#8220;test1&#8243;)<br />
}</p>
<p>For every single &#8216;create&#8217; there are two(!) INSERTs in the database, one to &#8216;child&#8217; and the other to the join table &#8216;chidren_parents&#8217;. If I use &#8216;import&#8217; as described in your article, the join table will not get updated, right?</p>
<p>Can this be solved somehow?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
