title: How can execute multiple statements in one query with Rails?
body: <p>I am using Ruby on Rails with ActiveRecord and PostgreSQL.</p>
  
  <p>How can i execute multiple sql queries?</p>
  
  <p>I need it for running a custom migration script, eg:  </p>
  
  <pre><code>Foo.connection.execute &lt;&lt;-SQL.split(';').map(&amp;:strip).join
   delete from metadata where record_type = 'Foo';
   TRUNCATE table1 RESTART IDENTITY;
   TRUNCATE table2 RESTART IDENTITY;
   delete from schema_migrations where version &gt; '20120806120823';
  SQL
  </code></pre>
  
  <p>I am not accepting data from a user, so I'm not worried about sql-injection.  </p>
  
  <p>Something like <a href="http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html" rel="noreferrer"><code>CLIENT_MULTI_STATEMENTS</code></a> in MySQL maybe ?</p>
  
  <p>From the MySQL/PHP docs:</p>
  
  <blockquote>
    <p><strong>CLIENT_MULTI_STATEMENTS</strong>: Tell the server that the client may send
    multiple statements in a single string (separated by “;”). If this
    flag is not set, multiple-statement execution is disabled. See the
    note following this table for more information about this flag.</p>
  </blockquote>