title: Rails - import CSV entry as array in PostgreSQL
body: <p>I'm using a Ruby on Rails rake task to import a .csv file into my PostgreSQL database. My code, for reference, is below:</p>
  
  <pre><code>require 'csv'    
  
  namespace :db do
      desc "Populate database"
      task populate_database: :environment do
  
          CSV.foreach("db.csv", :headers =&gt; true) do |row|
              Sale.create!(row.to_hash)
          end
  
      end
  end
  </code></pre>
  
  <p>In the .csv file, I have an entry in the format "cat; dog; foo; bar". Right now, this entry is being imported into PostgreSQL as "text" (i.e. the data type). However, I'd like for the text to be split at "; " and the results of the split to be stored in PostgreSQL as a text <strong><em>array</em></strong>.</p>
  
  <p>How do I go about doing this?</p>
  
  <p><strong>EDIT FOR CLARIFICATION:</strong></p>
  
  <p>My data looks something like this:</p>
  
  <pre><code>      column 1          | column 2    | column 3
  row 1 John              | Jack; Carol | Seth; Annie; Doug
  row 2 Jim; Cassie; Jane | Anne        | Laura; Bob
  </code></pre>
  
  <p>Right now, when I run my rake task, "John" goes into PostgreSQL as text. "Laura; Bob" also goes into PostgreSQL as text. However, I'd like for "Laura; Bob" (and, similarly, "Jack; Carol", "Seth; Annie; Doug", and "Jim; Cassie; Jane") to go into PostgreSQL as a text <strong>array</strong>. One such array would look like [Jack, Carol].</p>