Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 20A529FA38A; Wed, 11 Apr 2007 20:02:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 98678-02; Wed, 11 Apr 2007 20:02:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from vms044pub.verizon.net (vms044pub.verizon.net [206.46.252.44]) by postgresql.org (Postfix) with ESMTP id 258369FB888; Wed, 11 Apr 2007 20:02:24 -0300 (ADT) Received: from [192.168.7.5] ([71.101.4.76]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JGC00I9FVWRJI41@vms044.mailsrvcs.net>; Wed, 11 Apr 2007 18:00:28 -0500 (CDT) Date: Wed, 11 Apr 2007 19:00:23 -0400 From: Joe Subject: Re: [SQL] Urgent help in bit_string data type In-reply-to: To: Karthikeyan Sundaram Cc: pgsql-admin@postgresql.org, pgsql-sql@postgresql.org Message-id: <1176332423.782.10.camel@pampa> Organization: Freedom Circle, LLC MIME-version: 1.0 X-Mailer: Evolution 2.10.0 FreeBSD GNOME Team Port Content-type: text/plain Content-transfer-encoding: 7bit References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/106 X-Sequence-Number: 25170 Hi skarthi, On Wed, 2007-04-11 at 15:01 -0700, Karthikeyan Sundaram wrote: > create table test_a (b bit(3)); > > create view test_vw (b1, b2, b3) > as select > to_number(substring(b,1,1)::int,'9') as b1, > to_number(substring(b,2,1)::int,'9') as b2, > to_number(substring(b,3,1)::int,'9') as b3 from test_a; > > create or replace rule test_a_ins as on insert to test_vw > do instead > insert into test_a (b) values (COALESCE(new.b1::bit,'1')|| > COALESCE(new.b2::bit,'0')||COALESCE(new.b3::bit,'0')::bit); > > ERROR: cannot cast type numeric to bit > > How will I resolve this? *My* question is why are you doing such convoluted conversions, from bit string to text, then to int, etc.? It seems to me like you want to manipulate bits and if that's the case, you should be using the bit string operators, as someone pointed out a couple of days ago. In case you haven't looked at them, please see: http://www.postgresql.org/docs/8.2/static/functions-bitstring.html Joe