Skip site navigation (1) Skip section navigation (2)

Re: ALTER TABLE ( smallinto -> boolean ) ...

From: David Fetter <david(at)fetter(dot)org>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER TABLE ( smallinto -> boolean ) ...
Date: 2005-08-29 23:24:45
Message-ID: 20050829232445.GE13074@fetter.org (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-sql
On Mon, Aug 29, 2005 at 08:15:41PM -0300, Marc G. Fournier wrote:
> 
> I have a table with several 'smallint' fields that I'd like to convert to 
> booleean ... the data in each is either 0 or 1, and:
> 
> # select '1'::boolean;
>  bool
> ------
>  t
> (1 row)
> # select '0'::boolean;
>  bool
> ------
>  f
> (1 row)
> 
> so they do cast as expected ... but, if I try to do the ALTER, I get:
> 
> # ALTER TABLE table ALTER COLUMN field1 type boolean;
> ERROR:  column "field1" cannot be cast to type "pg_catalog.bool"

> Should this not work?  If not, is there a way to do it so that it will, 
> without having to reload the whole table?

ALTER TABLE "table" ALTER COLUMN field1 TYPE boolean
    USING CASE field1 WHEN 0 THEN false ELSE true END;
/* or something to this effect */

HTH :)

Cheers,
D
-- 
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

In response to

pgsql-hackers by date

Next:From: Rod TaylorDate: 2005-08-29 23:33:31
Subject: Re: ALTER TABLE ( smallinto -> boolean ) ...
Previous:From: Marc G. FournierDate: 2005-08-29 23:15:41
Subject: ALTER TABLE ( smallinto -> boolean ) ...

pgsql-sql by date

Next:From: Rod TaylorDate: 2005-08-29 23:33:31
Subject: Re: ALTER TABLE ( smallinto -> boolean ) ...
Previous:From: Marc G. FournierDate: 2005-08-29 23:15:41
Subject: ALTER TABLE ( smallinto -> boolean ) ...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group