pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedBit string help, please
7+ messages / 3 participants
[nested] [flat]
* Bit string help, please
@ 2008-03-05 22:17 tyrrill_ed@emc.com
2008-03-06 08:13 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
0 siblings, 1 reply; 7+ messages in thread
From: tyrrill_ed@emc.com @ 2008-03-05 22:17 UTC (permalink / raw)
To: pgsql-sql
Hey PostgreSQL Gurus,
I am experimenting with PostgreSQL bit strings to see if they might help
with some performance issues I am having. I added a "bit varying"
column to one of my tables. I have a PL/pgSQL function with an insert
statement into this table. For the bit varying column I would like to
insert a bit string of length n with the highest order bit being 1 and
all the other bits being 0. Given a table definition:
create table table1 (
a int,
b bit varying
);
I hoped I could use the feature where casting right pads 0s to do
something like this:
insert into table1 values( DEFAULT, B'1'::bit( n ) );
Where n is one of the parameters to the PL/pgSQL function, but that
doesn't work. PostgreSQL doesn't like having a variable for the bit
string length. Does anyone have any ideas how I could achieve this?
Thanks,
Ed Tyrrill
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Bit string help, please
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
@ 2008-03-06 08:13 ` Richard Huxton <dev@archonet.com>
2008-03-06 18:24 ` Re: Bit string help, please tyrrill_ed@emc.com
0 siblings, 1 reply; 7+ messages in thread
From: Richard Huxton @ 2008-03-06 08:13 UTC (permalink / raw)
To: tyrrill_ed@emc.com; +Cc: pgsql-sql
tyrrill_ed@emc.com wrote:
>
> insert into table1 values( DEFAULT, B'1'::bit( n ) );
>
> Where n is one of the parameters to the PL/pgSQL function, but that
> doesn't work. PostgreSQL doesn't like having a variable for the bit
> string length. Does anyone have any ideas how I could achieve this?
Try casting from a string:
SELECT ('1' || repeat('0', n-1))::bit varying;
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Bit string help, please
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
2008-03-06 08:13 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
@ 2008-03-06 18:24 ` tyrrill_ed@emc.com
2008-03-06 18:35 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
2008-03-06 18:50 ` Re: Bit string help, please Tena Sakai <tsakai@gallo.ucsf.edu>
0 siblings, 2 replies; 7+ messages in thread
From: tyrrill_ed@emc.com @ 2008-03-06 18:24 UTC (permalink / raw)
To: dev@archonet.com; +Cc: pgsql-sql
I tried this real quick at the psql command prompt, and unfortunately it
doesn't work:
mydb=# select ('1' || repeat('0',7))::bit varying;
ERROR: cannot cast type text to bit varying
I appreciate the try though. Any other ideas? I am using PostgreSQL
8.2.3.1. I don't know if that matters too much.
Thanks,
Ed
-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Thursday, March 06, 2008 12:14 AM
To: Tyrrill, Ed
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Bit string help, please
tyrrill_ed@emc.com wrote:
>
> insert into table1 values( DEFAULT, B'1'::bit( n ) );
>
> Where n is one of the parameters to the PL/pgSQL function, but that
> doesn't work. PostgreSQL doesn't like having a variable for the bit
> string length. Does anyone have any ideas how I could achieve this?
Try casting from a string:
SELECT ('1' || repeat('0', n-1))::bit varying;
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Bit string help, please
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
2008-03-06 08:13 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
2008-03-06 18:24 ` Re: Bit string help, please tyrrill_ed@emc.com
@ 2008-03-06 18:35 ` Richard Huxton <dev@archonet.com>
2008-03-06 18:52 ` Re: Bit string help, please tyrrill_ed@emc.com
1 sibling, 1 reply; 7+ messages in thread
From: Richard Huxton @ 2008-03-06 18:35 UTC (permalink / raw)
To: tyrrill_ed@emc.com; +Cc: pgsql-sql
tyrrill_ed@emc.com wrote:
> I tried this real quick at the psql command prompt, and unfortunately it
> doesn't work:
>
> mydb=# select ('1' || repeat('0',7))::bit varying;
> ERROR: cannot cast type text to bit varying
>
> I appreciate the try though. Any other ideas? I am using PostgreSQL
> 8.2.3.1. I don't know if that matters too much.
Ah, sorry - that was an 8.3-only cast.
I think your only real option will be to build your query as a string
and use EXECUTE to get the bit-varying you want in your function.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Bit string help, please
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
2008-03-06 08:13 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
2008-03-06 18:24 ` Re: Bit string help, please tyrrill_ed@emc.com
2008-03-06 18:35 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
@ 2008-03-06 18:52 ` tyrrill_ed@emc.com
2008-03-06 19:01 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
0 siblings, 1 reply; 7+ messages in thread
From: tyrrill_ed@emc.com @ 2008-03-06 18:52 UTC (permalink / raw)
To: dev@archonet.com; +Cc: pgsql-sql
Thanks for the help again, Richard. I will look into upgrading to 8.3
as I think that will be the best solution.
Ed Tyrrill
-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Thursday, March 06, 2008 10:36 AM
To: Tyrrill, Ed
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Bit string help, please
tyrrill_ed@emc.com wrote:
> I tried this real quick at the psql command prompt, and unfortunately
it
> doesn't work:
>
> mydb=# select ('1' || repeat('0',7))::bit varying;
> ERROR: cannot cast type text to bit varying
>
> I appreciate the try though. Any other ideas? I am using PostgreSQL
> 8.2.3.1. I don't know if that matters too much.
Ah, sorry - that was an 8.3-only cast.
I think your only real option will be to build your query as a string
and use EXECUTE to get the bit-varying you want in your function.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Bit string help, please
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
2008-03-06 08:13 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
2008-03-06 18:24 ` Re: Bit string help, please tyrrill_ed@emc.com
2008-03-06 18:35 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
2008-03-06 18:52 ` Re: Bit string help, please tyrrill_ed@emc.com
@ 2008-03-06 19:01 ` Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 7+ messages in thread
From: Richard Huxton @ 2008-03-06 19:01 UTC (permalink / raw)
To: tyrrill_ed@emc.com; +Cc: pgsql-sql
tyrrill_ed@emc.com wrote:
> Thanks for the help again, Richard. I will look into upgrading to 8.3
> as I think that will be the best solution.
I don't think you'll regret it. There are some excellent improvements in 8.3
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Bit string help, please
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
2008-03-06 08:13 ` Re: Bit string help, please Richard Huxton <dev@archonet.com>
2008-03-06 18:24 ` Re: Bit string help, please tyrrill_ed@emc.com
@ 2008-03-06 18:50 ` Tena Sakai <tsakai@gallo.ucsf.edu>
1 sibling, 0 replies; 7+ messages in thread
From: Tena Sakai @ 2008-03-06 18:50 UTC (permalink / raw)
To: tyrrill_ed@emc.com; dev@archonet.com; +Cc: pgsql-sql
Hi Ed,
I tried exactly what you did and it works for me.
My postgres is 8.3.0 running on redhat advanced
server. This is what it told me:
prompt=# SELECT ('1' || repeat('0', 7))::bit varying;
varbit
----------
10000000
(1 row)
prompt=#
Regards,
Tena Sakai
tsakai@gallo.ucsf.edu
-----Original Message-----
From: pgsql-sql-owner@postgresql.org on behalf of tyrrill_ed@emc.com
Sent: Thu 3/6/2008 10:24 AM
To: dev@archonet.com
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Bit string help, please
I tried this real quick at the psql command prompt, and unfortunately it
doesn't work:
mydb=# select ('1' || repeat('0',7))::bit varying;
ERROR: cannot cast type text to bit varying
I appreciate the try though. Any other ideas? I am using PostgreSQL
8.2.3.1. I don't know if that matters too much.
Thanks,
Ed
-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Thursday, March 06, 2008 12:14 AM
To: Tyrrill, Ed
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Bit string help, please
tyrrill_ed@emc.com wrote:
>
> insert into table1 values( DEFAULT, B'1'::bit( n ) );
>
> Where n is one of the parameters to the PL/pgSQL function, but that
> doesn't work. PostgreSQL doesn't like having a variable for the bit
> string length. Does anyone have any ideas how I could achieve this?
Try casting from a string:
SELECT ('1' || repeat('0', n-1))::bit varying;
--
Richard Huxton
Archonet Ltd
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://mail.postgresql.org/mj/mj_wwwusr?domain=postgresql.org&extra=pgsql-sql
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2008-03-06 19:01 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-03-05 22:17 Bit string help, please tyrrill_ed@emc.com
2008-03-06 08:13 ` Richard Huxton <dev@archonet.com>
2008-03-06 18:24 ` tyrrill_ed@emc.com
2008-03-06 18:35 ` Richard Huxton <dev@archonet.com>
2008-03-06 18:52 ` tyrrill_ed@emc.com
2008-03-06 19:01 ` Richard Huxton <dev@archonet.com>
2008-03-06 18:50 ` Tena Sakai <tsakai@gallo.ucsf.edu>
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