title: PostgreSQL can't cast type json to character varying[]
body: <p><strong>In my Rails 5.0.5 app I need to convert <code>json</code> column into <code>string, array: true</code>.</strong></p>
  
  <p>The values in my <code>json</code> columns are like:</p>
  
  <pre><code>[ "200px-RR5219-0015R.png", "2017_03_25_2235.doc", "137555.jpg" ]
  </code></pre>
  
  <p>I tried this migration:</p>
  
  <pre class="lang-rb prettyprint-override"><code>class ChangeTaskAttachmentsTypeToString &lt; ActiveRecord::Migration[5.0]
    def change
      change_column :tasks, :attachments, :string, array: true
    end
  end
  </code></pre>
  
  <p>and got this error:</p>
  
  <pre><code>ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR:  column "attachments" cannot be cast automatically to type character varying[]
  HINT:  You might need to specify "USING attachments::character varying[]".
  : ALTER TABLE "tasks" ALTER COLUMN "attachments" TYPE character varying[]
  </code></pre>
  
  <p>Then I edited migration:</p>
  
  <pre class="lang-rb prettyprint-override"><code>class ChangeTaskAttachmentsTypeToString &lt; ActiveRecord::Migration[5.0]
    def change
      change_column :tasks, :attachments, 'character varying[] USING attachments::character varying[]' 
    end
  end
  </code></pre>
  
  <p>And finally got this error:</p>
  
  <pre><code>PG::CannotCoerce: ERROR:  cannot cast type json to character varying[]
  : ALTER TABLE "tasks" ALTER COLUMN "attachments" TYPE character varying[] USING attachments::character varying[]
  </code></pre>
  
  <p><strong>How can I do this migration?</strong></p>