title: Rails 4 / postgresql 9.4 - Query and update a ruby object inside an array
body: <p>I have a method (find_by_sql) that outputs <strong>a ruby object inside an array</strong> like this:</p>
  
  <pre><code>[#&lt;deal id: 66480, opportunity_id: 4, admin_user_id: 1, created_at: "2015-09-20 18:37:29", updated_at: "2015-09-20 18:37:29", deal_available: true&gt;]
  </code></pre>
  
  <p>How can I update the object's 'deal_available' attribute inside my database in raw postgresql ?</p>
  
  <p>I tried different ways to write it but I stumble on the fact that it's very specific: it's an array, and inside there is a ruby object and I must manage to tell postgresql to <strong>change the value of deal_available: true to deal_available: false.</strong></p>
  
  <p>In local, I tried:  logger.debug "Here is the resulting object for update:</p>
  
  <pre><code> #{@deal_question[0]}
  </code></pre>
  
  <p>but I get:</p>
  
  <pre><code>#&lt;@deal_question:0x007fd9b3963270&gt;
  </code></pre>
  
  <p>Here is how @deal_question is created</p>
  
  <pre><code>@deal_question = Deal.find_by_sql(
        " SELECT \"deals\".*
          FROM \"deals\"
          WHERE (opportunity_id = #{@deal.id}
          AND deal_available = true)
          ORDER BY \"deals\".\"id\" ASC LIMIT 1"
      ) 
  </code></pre>
  
  <p>I don't even have a postgresql query to suggest here because first I need to understand how to query this ruby object inside the array.</p>