<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Lucky-Dip Blog: Read table row-by-row in ruby</title>
    <link>http://blog.lucky-dip.net/articles/2008/03/12/read-table-row-by-row-in-ruby</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Read table row-by-row in ruby</title>
      <description>&lt;p&gt;
I needed to export some data from a huge data table. Iterating through MyModel.find took too long and too much ram, so I went straight to the db instead. 
&lt;/p&gt;

Example code was tough to find, so here's an example:

&lt;pre class="code"&gt;
sql = "select * from #{ MyModel.table_name }"
MyModel.connection.execute(sql) do |handle|
  handle.fetch do |row|
    # row is an array of values
    ... export row ...
  end
end
&lt;/pre&gt;

</description>
      <pubDate>Wed, 12 Mar 2008 12:00:00 +1100</pubDate>
      <guid isPermaLink="false">urn:uuid:7f1cc0c7-4146-4e78-ab19-e968710cb720</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2008/03/12/read-table-row-by-row-in-ruby</link>
      <category>ruby</category>
      <category>rails</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/10</trackback:ping>
    </item>
  </channel>
</rss>
