title: Prepare and execute statements with ActiveRecord using PostgreSQL
body: <p>I am trying to insert values via a prepared statement using ActiveRecord. However, everytime I try:</p>
  
  <pre><code>conn = ActiveRecord::Base.connection
  conn.prepare "SELECT * from sampletable where id = $1"
  conn.execute 3
  </code></pre>
  
  <p>After the second statement, I get:</p>
  
  <pre><code>NoMethodError: undefined method `prepare' for
  #&lt;ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x000001027442c8&gt;
  </code></pre>
  
  <p>What should I do? I'm running Rails 3.2.1 and Ruby 1.9.2</p>
  
  <p>UPDATE:</p>
  
  <p>I solved the problem. Thanks for the response, but it didn't work for PostgreSQL. The way to do it is:</p>
  
  <pre><code>stmt = "SELECT * from sampletable where id = $1 and name = $2"
  values = [ { value: 1}, { value: "henry" } ]
  </code></pre>
  
  <p>where values is an array of hashes, each specifying a value, $1 is bound to the 0th hash, $2 is bound to the 2nd hash in the array and so on</p>
  
  <pre><code>con = PG::Connection.new(:dbname =&gt; "development_DB")
  con.prepare("insert", stmt)
  con.exec_prepared("insert", values)
  con.close()
  </code></pre>
  
  <p>And this, ladies and gentlemen, works!</p>