On Mon, Dec 16, 2013 at 7:48 PM, Mike Vezzani <lists / ruby-forum.com> wrote:

> Fascinating. Thanks for the suggested solution, Joel. I am curious to
> know why the hash from #view_library1 includes duplicate information.
> Any thoughts as to why that might be?
>
> --
> Posted via http://www.ruby-forum.com/.
>


Setting results_as_hash gives you a hash with both column name and column
index as keys into the fields in each record returned. The data is not
duplicated in the database, but shows up twice in the hash with the alpha
and numeric indeces.

  p books[0][0] # => 1
  p books[0]['id'] #=> 1

  p books[0][1] # => "The Spirit Catches You and You Fall Down"
  p books[0]['title'] #  => "The Spirit Catches You and You Fall Down"

This is what setting results_as_hash does, in fact. If you wanted each
record to be an array of column values, you'd set results_as_hash false.