title: How can I convert all SMALLINT columns in PostgreSQL database to BOOLEAN?
body: <p>I migrated my Django website database <strong>from MySQL to PostgreSQL</strong> using a third party tool <strong>pgloader</strong>. But since MySQL stores <strong>BOOLEAN</strong> data as <strong>TINYINT</strong> by default(at least with Django), it got converted to <strong>SMALLINT</strong> in PostgreSQL. Now Django is showing error that <strong>smallint is being treated as boolean</strong>. Due to this, I want to convert all smallint columns to boolean. Is there a single command to convert all columns in all tables in a single database to required type? If I have to perform the operation separately for each table, that's OK too.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Column structure:</p>
  
  <p><code>public            | smallint                 | default '1'::smallint</code></p>
  
  <p>Here <strong>public</strong> is column name, <strong>smallint</strong> it's type and has it <strong>default value of '1'</strong>.</p>
  
  <p>The code I used:</p>
  
  <pre><code>utkarsh@utkarsh-Lenovo-G580:~$ psql -d thakurani -U utkarsh
  Password for user utkarsh: 
  psql (9.6.3)
  Type "help" for help.
  
  thakurani=# alter table topics_topic alter COLUMN public type boolean using(public::text::boolean);                             ERROR:  default for column "public" cannot be cast automatically to type boolean
  thakurani=# alter table topics_topic alter COLUMN public type text using(public::text);
  ALTER TABLE
  thakurani=# alter table topics_topic alter COLUMN public type boolean using(public::boolean);
  ERROR:  default for column "public" cannot be cast automatically to type boolean
  thakurani=# ALTER TABLE topics_topic ALTER COLUMN public TYPE boolean USING CASE WHEN public = '0' THEN FALSE WHEN public = '1' THEN TRUE END;
  ERROR:  default for column "public" cannot be cast automatically to type boolean
  thakurani=# 
  </code></pre>