pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe <dev@freedomcircle.net>
To: Karthikeyan Sundaram <skarthi98@hotmail.com>
Cc: pgsql-admin@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Urgent help in bit_string data type
Date: Thu, 12 Apr 2007 00:07:07 -0400
Message-ID: <1176350827.782.37.camel@pampa> (raw)
In-Reply-To: <BAY131-W9661010BCB5108028C3FFB05F0@phx.gbl>
References: <BAY131-W9661010BCB5108028C3FFB05F0@phx.gbl>

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




view thread (6+ messages)

Message-ID: <1176350827.782.37.camel@pampa>
Permalink:  ../1176350827.782.37.camel@pampa/
Also on:    postgresql.org/message-id/1176350827.782.37.camel@pampa

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@freedomcircle.net, skarthi98@hotmail.com, pgsql-admin@postgresql.org
  Subject: Re: [SQL] Urgent help in bit_string data type
  In-Reply-To: <1176350827.782.37.camel@pampa>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox