From skarthi98@hotmail.com Wed Apr 11 20:31:05 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 4902F9FB688; Wed, 11 Apr 2007 17:31:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 71054-04; Wed, 11 Apr 2007 17:30:55 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from bay0-omc3-s27.bay0.hotmail.com (bay0-omc3-s27.bay0.hotmail.com [65.54.246.227]) by postgresql.org (Postfix) with ESMTP id 738499FB59A; Wed, 11 Apr 2007 17:30:58 -0300 (ADT) Received: from BAY131-W10 ([65.55.136.45]) by bay0-omc3-s27.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed, 11 Apr 2007 13:30:57 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_212de693-e805-4486-9f36-dab2ab602055_" X-Originating-IP: [67.116.31.14] From: Karthikeyan Sundaram To: , Subject: Urgent help in bit_string data type Date: Wed, 11 Apr 2007 13:30:57 -0700 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 11 Apr 2007 20:30:57.0005 (UTC) FILETIME=[4F3399D0:01C77C78] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.948 tagged_above=0 required=5 tests=AWL=-1.272, BAYES_40=-0.185, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, HTML_40_50=0.496, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200704/102 X-Sequence-Number: 25166 --_212de693-e805-4486-9f36-dab2ab602055_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Gurus, =20 I have a table with datatype as bitstrings =20 =20 create table test_a (b bit(3)); =20 insert into test_a values ('111'); This will convert a bit to a number =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D select to_number((substring(b,1,1)::int),9)+3 from test_a; How will I convert a Number to a bit ---------------------------------- =20 insert into test_a values (to_char(1,'9')); =20 ERROR: column "b" is of type bit but expression is of type textHINT: You = will need to rewrite or cast the expression. =20 Please help me =20 regards skarthi =20 _________________________________________________________________ i'm making a difference.=A0Make every IM count for the cause of your choice= . Join Now. http://clk.atdmt.com/MSN/go/msnnkwme0080000001msn/direct/01/?href=3Dhttp://= im.live.com/messenger/im/home/?source=3Dwlmailtagline= --_212de693-e805-4486-9f36-dab2ab602055_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi Gurus,
 
   I have a table with datatype as bitstrings
 
 
create table test_a (b bit(3));
 
insert into test_a values ('111');

This will convert a bit to a number
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D
select to_number((substring(b,1,1)::int),9)+3 from test_a;

How will I convert a Number to a bit
----------------------------------
 
insert into test_a values (to_char(1,'9'));
 
ERROR:  column "b" is of type bit but expression is of type text
HI= NT:  You will need to rewrite or cast the expression.
 
Please help me
 
regards
skarthi
 


i'm making a difference.=A0Make every IM= count for the cause of your choice. Join Now. = --_212de693-e805-4486-9f36-dab2ab602055_-- From dev@freedomcircle.net Wed Apr 11 21:44:13 2007 Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B20239FB55E; Wed, 11 Apr 2007 18:44:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36474-03; Wed, 11 Apr 2007 18:44:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by postgresql.org (Postfix) with ESMTP id 81EE29FB54B; Wed, 11 Apr 2007 18:44:09 -0300 (ADT) Received: from [192.168.7.5] ([71.101.4.76]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JGC00GTSSDHCZQE@vms046.mailsrvcs.net>; Wed, 11 Apr 2007 16:44:08 -0500 (CDT) Date: Wed, 11 Apr 2007 17:44:01 -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: <1176327841.782.2.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/104 X-Sequence-Number: 25168 Hi skarthi, On Wed, 2007-04-11 at 13:30 -0700, Karthikeyan Sundaram wrote: > insert into test_a values (to_char(1,'9')); > > ERROR: column "b" is of type bit but expression is of type > text > HINT: You will need to rewrite or cast the expression. As suggested by the error, you should use a cast, e.g., insert into test_a values 9::bit(3); This will result in binary '001' being inserted because you need 4 bits to represent decimal 9. Joe From skarthi98@hotmail.com Wed Apr 11 22:01:25 2007 Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 565C79FB946; Wed, 11 Apr 2007 19:01:25 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 47754-05; Wed, 11 Apr 2007 19:01:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from bay0-omc1-s18.bay0.hotmail.com (bay0-omc1-s18.bay0.hotmail.com [65.54.246.90]) by postgresql.org (Postfix) with ESMTP id 524389FB941; Wed, 11 Apr 2007 19:01:09 -0300 (ADT) Received: from BAY131-W4 ([65.55.136.39]) by bay0-omc1-s18.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed, 11 Apr 2007 15:01:07 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_c063acbb-4e48-4d25-b726-bfc344d9fba0_" X-Originating-IP: [67.116.31.14] From: Karthikeyan Sundaram To: Joe CC: , Subject: Re: [SQL] Urgent help in bit_string data type Date: Wed, 11 Apr 2007 15:01:07 -0700 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 11 Apr 2007 22:01:07.0476 (UTC) FILETIME=[E817F540:01C77C84] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.273 tagged_above=0 required=5 tests=AWL=-0.526, BAYES_05=-1.11, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200704/105 X-Sequence-Number: 25169 --_c063acbb-4e48-4d25-b726-bfc344d9fba0_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks Joe, =20 Here is my next question. =20 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 in= sert to test_vwdo insteadinsert into test_a (b) values (COALESCE(new.b1::bi= t,'1')||COALESCE(new.b2::bit,'0')||COALESCE(new.b3::bit,'0')::bit); ERROR: cannot cast type numeric to bit =20 How will I resolve this? =20 Regards skarthi > Date: Wed, 11 Apr 2007 17:44:01 -0400> From: dev@freedomcircle.net> Subje= ct: Re: [ADMIN] [SQL] Urgent help in bit_string data type> To: skarthi98@ho= tmail.com> CC: pgsql-admin@postgresql.org; pgsql-sql@postgresql.org> > Hi s= karthi,> > On Wed, 2007-04-11 at 13:30 -0700, Karthikeyan Sundaram wrote:> = > insert into test_a values (to_char(1,'9'));> > > > ERROR: column "b" is o= f type bit but expression is of type> > text> > HINT: You will need to rewr= ite or cast the expression.> > As suggested by the error, you should use a = cast, e.g.,> > insert into test_a values 9::bit(3);> > This will result in = binary '001' being inserted because you need 4 bits> to represent decimal 9= .> > Joe> > > ---------------------------(end of broadcast)----------------= -----------> TIP 6: explain analyze is your friend _________________________________________________________________ Take a break and play crossword puzzles - FREE! http://games.msn.com/en/flexicon/default.htm?icid=3Dflexicon_ wlmemailtagli= nemarch07= --_c063acbb-4e48-4d25-b726-bfc344d9fba0_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks Joe,
 
  Here is my next question.
 
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 repl= ace rule test_a_ins as on insert to test_vw
do instead
insert into te= st_a (b) values (COALESCE(new.b1::bit,'1')||COALESCE(new.b2::bit,'0')||COAL= ESCE(new.b3::bit,'0')::bit);

ERROR:  cannot cast type numeric to bit
 
How will I resolve this?
 
Regards
skarthi

> Date: Wed, 11 Apr 2007 17:44:01 -0400
> From: dev@freedomcir= cle.net
> Subject: Re: [ADMIN] [SQL] Urgent help in bit_string data t= ype
> To: skarthi98@hotmail.com
> CC: pgsql-admin@postgresql.or= g; pgsql-sql@postgresql.org
>
> Hi skarthi,
>
> O= n Wed, 2007-04-11 at 13:30 -0700, Karthikeyan Sundaram wrote:
> > = insert into test_a values (to_char(1,'9'));
> >
> > ERRO= R: column "b" is of type bit but expression is of type
> > text> > HINT: You will need to rewrite or cast the expression.
> <= BR>> As suggested by the error, you should use a cast, e.g.,
> > insert into test_a values 9::bit(3);
>
> This will resul= t in binary '001' being inserted because you need 4 bits
> to represe= nt decimal 9.
>
> Joe
>
>
> --------------= -------------(end of broadcast)---------------------------
> TIP 6: e= xplain analyze is your friend



Take a break and play cros= sword puzzles - FREE! Play Now! = --_c063acbb-4e48-4d25-b726-bfc344d9fba0_-- From dev@freedomcircle.net Wed Apr 11 23:02:28 2007 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 From skarthi98@hotmail.com Wed Apr 11 23:29:51 2007 Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 6CDF19FB4E0; Wed, 11 Apr 2007 20:29:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 68913-05; Wed, 11 Apr 2007 20:29:47 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from bay0-omc1-s12.bay0.hotmail.com (bay0-omc1-s12.bay0.hotmail.com [65.54.246.84]) by postgresql.org (Postfix) with ESMTP id 54B309FB4E4; Wed, 11 Apr 2007 20:29:47 -0300 (ADT) Received: from BAY131-W9 ([65.55.136.44]) by bay0-omc1-s12.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed, 11 Apr 2007 16:29:45 -0700 Message-ID: Content-Type: multipart/alternative; boundary="_21f6fa5e-03ff-4ba2-b02e-4d2cf4dcf61e_" X-Originating-IP: [67.116.31.14] From: Karthikeyan Sundaram To: Joe CC: , Subject: Re: [SQL] Urgent help in bit_string data type Date: Wed, 11 Apr 2007 16:29:45 -0700 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 11 Apr 2007 23:29:45.0741 (UTC) FILETIME=[4A06CBD0:01C77C91] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/107 X-Sequence-Number: 25171 --_21f6fa5e-03ff-4ba2-b02e-4d2cf4dcf61e_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Joe, =20 The reason why I am asking is, we are building an interface layer where a= ll 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. =20 That's the reason. =20 Regards skarthi> Date: Wed, 11 Apr 2007 19:00:23 -0400> From: dev@freedomcircle.net= > Subject: Re: [ADMIN] [SQL] Urgent help in bit_string data type> To: skart= hi98@hotmail.com> CC: pgsql-admin@postgresql.org; pgsql-sql@postgresql.org>= > Hi skarthi,> > On Wed, 2007-04-11 at 15:01 -0700, Karthikeyan Sundaram w= rote:> > 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_nu= mber(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 inser= t to test_vw> > do instead> > insert into test_a (b) values (COALESCE(new.b= 1::bit,'1')||> > COALESCE(new.b2::bit,'0')||COALESCE(new.b3::bit,'0')::bit)= ;> > > > ERROR: cannot cast type numeric to bit> > > > How will I resolve t= his?> > *My* question is why are you doing such convoluted conversions, fro= m 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> > > ---------------------------(end of br= oadcast)---------------------------> TIP 6: explain analyze is your friend _________________________________________________________________ Live Search Maps =96 find all the local information you need, right when yo= u need it. http://maps.live.com/?icid=3Dwlmtag2&FORM=3DMGAC01= --_21f6fa5e-03ff-4ba2-b02e-4d2cf4dcf61e_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Joe,
 
  The reason why I am asking is, we are building an interface layer wh= ere all our users will have a view.  They shouldn't know anything abou= t how and where the data is stored in the table.  They can be seen onl= y by the portal which will use view.
 
    That's the reason.
 
Regards
skarthi

> Date: Wed, 11 Apr 2007 19:00:23 -0400
> From: dev= @freedomcircle.net
> Subject: Re: [ADMIN] [SQL] Urgent help in bit_st= ring data type
> To: skarthi98@hotmail.com
> CC: pgsql-admin@po= stgresql.org; pgsql-sql@postgresql.org
>
> Hi skarthi,
>=
> On Wed, 2007-04-11 at 15:01 -0700, Karthikeyan Sundaram wrote:> > create table test_a (b bit(3));
> >
> > creat= e 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 fro= m test_a;
> >
> > create or replace rule test_a_ins as o= n 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: ca= nnot 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 t= o me like you want to
> manipulate bits and if that's the case, you s= hould be using the bit
> string operators, as someone pointed out a c= ouple of days ago. In case
> you haven't looked at them, please see:<= BR>>
> http://www.postgresql.org/docs/8.2/static/functions-bitstr= ing.html
>
> Joe
>
>
> -------------------= --------(end of broadcast)---------------------------
> TIP 6: explai= n analyze is your friend



Live Search Maps =96 find all t= he local information you need, right when you need it. Find it! = --_21f6fa5e-03ff-4ba2-b02e-4d2cf4dcf61e_-- From dev@freedomcircle.net Thu Apr 12 04:07:35 2007 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