title: Rails Migration - Change Integer Column to Array Integer - Postgres
body: <p>I have a benefit_type integer column in Provider Model Which is a enum column. </p>
  
  <p>Provider.rb</p>
  
  <pre><code>enum: ['abc', 'bcd']
  </code></pre>
  
  <p>Now I want to migrate to array_enum </p>
  
  <p>Provider.rb</p>
  
  <pre><code>array_enum: {'abc': 0, 'bcd': 1}
  </code></pre>
  
  <p>So, to accommodate this change I want to change my column to array of integer. In my migration I have,</p>
  
  <pre><code>change_column :providers, :benefit_type, :integer, array: true, default: {}, using: "(string_to_array(benefit_type, ','))"
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> Caused by:
  PG::UndefinedFunction: ERROR:  function string_to_array(integer, unknown) does not exist
  LINE 1: ...ALTER COLUMN "benefit_type" TYPE integer[] USING (string_to_...
                                                           ^
  HINT:  No function matches the given name and argument types. You might need to add explicit 
  type casts.
  </code></pre>
  
  <p>Also tried:</p>
  
  <pre><code>   change_column :providers, :benefit_type, :integer, array: true, default: []
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> Caused by:
  ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR:  column "benefit_type" cannot 
  be cast automatically to type integer[]
  HINT:  You might need to specify "USING benefit_type::integer[]".
  : ALTER TABLE "providers" ALTER COLUMN "benefit_type" TYPE integer[], ALTER COLUMN 
  "benefit_type" SET DEFAULT '{}'
  </code></pre>