Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 99B469FB92D; Thu, 12 Apr 2007 01:07:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 16740-07; Thu, 12 Apr 2007 01:07:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from vms042pub.verizon.net (vms042pub.verizon.net [206.46.252.42]) by postgresql.org (Postfix) with ESMTP id 2ED959FB8E9; Thu, 12 Apr 2007 01:07:29 -0300 (ADT) Received: from [192.168.7.5] ([71.101.4.76]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JGD00DRTA3ZOSH5@vms042.mailsrvcs.net>; Wed, 11 Apr 2007 23:07:12 -0500 (CDT) Date: Thu, 12 Apr 2007 00:07:07 -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: <1176350827.782.37.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/111 X-Sequence-Number: 25175 Hi skarthi, On Wed, 2007-04-11 at 16:29 -0700, Karthikeyan Sundaram wrote: > The reason why I am asking is, we are building an interface layer > where all our users will have a view. They shouldn't know anything > about how and where the data is stored in the table. They can be seen > only by the portal which will use view. > > That's the reason. I can understand using views to hide data from users, but that was not what I was asking about. It seems that you still have not read the page that we referenced. Consider the following: test=> create table test_a (b bit(3)); CREATE TABLE test=> insert into test_a values (b'001'); INSERT 0 1 test=> insert into test_a values (b'010'); INSERT 0 1 test=> insert into test_a values (b'101'); INSERT 0 1 test=> select * from test_a; b ----- 001 010 101 (3 rows) test=> create or replace view test_vw as test-> select b::bit(1) as b2, (b<<1)::bit(1) as b1, test-> (b<<2)::bit(1) as b0 from test_a; CREATE VIEW test=> select * from test_vw; b2 | b1 | b0 ----+----+---- 0 | 0 | 1 0 | 1 | 0 1 | 0 | 1 (3 rows) The view above gives the same results as your original view, but only uses bit manipulations (and the only counterintuitive part is ::bit(1) gives you the MSB). Your view has to convert a bit string to text (or maybe bytea) for the substring function, then it has to convert the text to int because of your explicit cast, and finally it has to convert back to text for the to_number function. The result of to_number is numeric and you're trying to cast it to bit, which is what the ERROR was telling you can't do. Joe