X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 551DCD7ECF; Mon, 29 Aug 2005 20:24:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31614-02; Mon, 29 Aug 2005 23:24:49 +0000 (GMT) Received: from fetter.org (dsl092-188-065.sfo1.dsl.speakeasy.net [66.92.188.65]) by svr1.postgresql.org (Postfix) with ESMTP id 54195D6E21; Mon, 29 Aug 2005 20:24:47 -0300 (ADT) Received: from fetter.org (localhost.localdomain [127.0.0.1]) by fetter.org (8.13.4/8.12.10) with ESMTP id j7TNOjnY018648; Mon, 29 Aug 2005 16:24:45 -0700 Received: (from shackle@localhost) by fetter.org (8.13.4/8.13.4/Submit) id j7TNOjN9018647; Mon, 29 Aug 2005 16:24:45 -0700 Date: Mon, 29 Aug 2005 16:24:45 -0700 From: David Fetter To: "Marc G. Fournier" Cc: pgsql-hackers@postgresql.org Subject: Re: ALTER TABLE ( smallinto -> boolean ) ... Message-ID: <20050829232445.GE13074@fetter.org> References: <20050829201253.X1044@ganymede.hub.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050829201253.X1044@ganymede.hub.org> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.06 required=5 tests=[AWL=0.010, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/1075 X-Sequence-Number: 72270 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@fetter.org http://fetter.org/ phone: +1 510 893 6100 mobile: +1 415 235 3778 Remember to vote!