title: Retrieve the nextval from a sequence using activerecord in Ruby on Rails 3.2.14 / Ruby 2.0.0 / PostgreSQL 9.2.4
body: <p>This should be SO simple.  I want to retrieve the nextval of a sequence... it's not a default value... it's not a primary key... it's not a foreign key.  In rare cases, I need a sequence number for a user supplied value.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>@nextid = ActiveRecord::Base.connection.execute("SELECT nextval('xscrpt_id_seq')")
  </code></pre>
  
  <p>and what I get back is:</p>
  
  <pre><code>#&lt;PG::Result:0x007fe668a854e8 @connection=#&lt;PG::Connection:0x00000003aeff30&gt;&gt;
  </code></pre>
  
  <p>And by using</p>
  
  <pre><code>@nextid[0]["nextval"]
  </code></pre>
  
  <p>I can get the correct value, but it doesn't seem like the right way to approach the problem.  I've searched, I read "Pro Active Record", which said to use:</p>
  
  <pre><code>M_script.find_by_sql("SELECT nextval('xscript_id_seq')")
  </code></pre>
  
  <p>but, that didn't work.</p>
  
  <p>Any hints on the "correct" (Rails way) to retrieve a nextval from a sequence in ROR, would be very appreciated!</p>