title: Upgrading a varchar column to enum type in postgresql
body: <p>We have a varchar column in a table, that we need to upgrade to enum type.</p>
  
  <p>All the values in the varchar column are valid values in the enumeration. There is no null values in the varchar column.</p>
  
  <pre><code>ALTER TABLE tableName
     ALTER COLUMN varcharColumn TYPE enum_type
  </code></pre>
  
  <p><strong>ERROR: column "varcharColumn" cannot be cast to type enum_type
  SQL state: 42804</strong></p>
  
  <p>The round about way is to</p>
  
  <ol>
  <li>Create another new column with enum type.</li>
  <li>Update the enum type column with the varchar column after typecasting.</li>
  <li>Drop the varchar column.</li>
  <li>Rename the enum type column name to the varchar column name.</li>
  </ol>
  
  <p>Is there a better way to achieve this?</p>
  
  <p>Thanks in advance. </p>