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 DA4F3D88D0; Thu, 1 Sep 2005 18:23:24 -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 25203-07; Thu, 1 Sep 2005 21:23:19 +0000 (GMT) Received: from trolak.mydnsbox2.com (ns1.mydnsbox2.com [207.44.142.118]) by svr1.postgresql.org (Postfix) with ESMTP id CE238D888B; Thu, 1 Sep 2005 18:23:17 -0300 (ADT) Received: from [192.168.1.103] (cpe-024-211-165-134.nc.res.rr.com [24.211.165.134]) (authenticated (0 bits)) by trolak.mydnsbox2.com (8.11.6/8.11.6) with ESMTP id j81KdKq07880; Thu, 1 Sep 2005 15:39:20 -0500 Message-ID: <4317713C.10808@dunslane.net> Date: Thu, 01 Sep 2005 17:23:08 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050719 Fedora/1.7.10-1.3.1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: "Marc G. Fournier" , pgsql-hackers@postgresql.org Subject: Re: ALTER TABLE ( smallinto -> boolean ) ... References: <20050829201253.X1044@ganymede.hub.org> <15013.1125359379@sss.pgh.pa.us> <20050901174341.N1044@ganymede.hub.org> <6399.1125608205@sss.pgh.pa.us> In-Reply-To: <6399.1125608205@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.044 required=5 tests=[AWL=0.044] X-Spam-Level: X-Archive-Number: 200509/81 X-Sequence-Number: 72478 Tom Lane wrote: >"Marc G. Fournier" writes: > > >>On Mon, 29 Aug 2005, Tom Lane wrote: >> >> >>>No, because there's no built-in cast from smallint to bool. >>> >>> > > > >>'k, I just took a read through the "CREATE CAST" man page, and don't think >>I can use that for this, >> >> > >Sure you can. Make a SQL or PLPGSQL function that does the conversion >you want and then create a cast using it. > > That probably won't help him much with "values(0)": andrew=# create function ibool(smallint) returns boolean language sql as $$ select $1 <> 0 $$; CREATE FUNCTION andrew=# create cast (smallint as boolean) with function ibool(smallint) as implicit; CREATE CAST andrew=# insert into foobool values(0); ERROR: column "x" is of type boolean but expression is of type integer HINT: You will need to rewrite or cast the expression. Is there a way to make the builtin int to bool cast implicit? cheers andrew