pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Brannen <kevinb@nurseamerica.net>
To: pgsql-sql@postgresql.org
Subject: Re: bit field changes in 7.2.1
Date: Mon, 08 Jul 2002 10:10:46 -0500
Message-ID: <3D29AB76.4000502@nurseamerica.net> (raw)
References: <Pine.LNX.4.44.0207070003530.929-100000@localhost.localdomain>

Peter Eisentraut wrote:
> Kevin Brannen writes:
> 
> 
>>EXCEPT that now fails in 7.2.1 (I just upgraded this afternoon).  It
>>forces me to use "b'000000'" instead of "b'0'::bit(6)".
> 
> 
> Which is a problem why?

Because in the real system, it will be b'0'::bit(64) or b'001::bit(64) 
or etc.  A bit nasty to type isn't it. :-)  And of course that's for 1 
table, in another place it be 40 bits wide, and in yet a third 96 bits 
wide.  So a simple mechanism to make it the correct size (for 
comparisons) is very useful (to maintain my sanity. :-)

...
> 
> 
> In your case the solution is to type the six zeroes.
> 
> The comment referred to cases where the results of computations needed to
> be forced to the right length, in which case you could use something like
> 
>       substring(computation() || b'000000' for 6)
> 
> The question whether the constant should go before or after the
> computation, and whether it should be zeros or ones is a matter of taste,
> which is why an example has been omitted.
> 

I'm still not sure I see the problem, but that doesn't really matter. 
If that's the explanation, then *that* should have been included with 
the note, IMO.  OTOH, I still don't see where that helps me.  How does 
it give me a string of bits like b'0'::64 does, or b'1'::64 does?  And 
something like:

select substring(1 || b'000000' for 6);

assuming some computation returns a "1", tells me:

ERROR:  Unable to identify an operator '||' for types 'integer' and 
'bit'   You will have to retype this query using an explicit cast


In an email, Chris suggested using rpad(), which looks good but doesn't 
quite work, unless I'm overlooking something (if so, pleeeeease point it 
out!).  When I try it in my query I get:

select ... from ...
where sp.bitmask != cast(rpad('0',6,'0') as bit(6));

ERROR:  Cannot cast type 'text' to 'bit'


<whine>
I guess my issue is that when some feature is taken out, there needs to 
be another way to do it, AND it needs to be documented.  Or just leave 
it in and flag it as an extension.
</whine> ;-)

I guess I'll just have to read the bits in from the DB reference table, 
then store and manipulate them all in Perl...sigh...

Thanks for the effort though!
Kevin






view thread (3+ messages)

Message-ID: <3D29AB76.4000502@nurseamerica.net>
Permalink:  ../3D29AB76.4000502@nurseamerica.net/
Also on:    postgresql.org/message-id/3D29AB76.4000502@nurseamerica.net

 · 

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: kevinb@nurseamerica.net
  Subject: Re: bit field changes in 7.2.1
  In-Reply-To: <3D29AB76.4000502@nurseamerica.net>

* 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