Re: BUG #3765: strange results for bit string hex notation cast to bit

From: Cade Cairns <cadec(at)otii(dot)com>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3765: strange results for bit string hex notation cast to bit
Date: 2007-11-20 21:47:46
Message-ID: 24B6EF3D-B0BC-44EB-ADD1-257AE9A51FD4@otii.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Can anyone explain why this is the case?

On 20-Nov-07, at 2:42 PM, Heikki Linnakangas wrote:

> Cade Cairns wrote:
>> When casting a bit string constant using hexadecimal notation to a
>> longer
>> bit string, the result is padded with 0's on the right. This will
>> result in
>> inconsistent/useless results:
>> test=# select x'ff'::integer;
>> int4 ------
>> 255
>> (1 row)
>> test=# select x'ff'::bit(16)::integer;
>> int4 -------
>> 65280
>> (1 row)
>
> It works like it should according to the manual:
>
> http://www.postgresql.org/docs/8.1/interactive/datatype-bit.html
>
> "Note: If one explicitly casts a bit-string value to bit(n), it
> will be truncated or zero-padded on the right to be exactly n bits,
> without raising an error. Similarly, if one explicitly casts a bit-
> string value to bit varying(n), it will be truncated on the right if
> it is more than n bits."
>
> --
> Heikki Linnakangas
> EnterpriseDB http://www.enterprisedb.com
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2007-11-20 22:28:23 Re: BUG #3765: strange results for bit string hex notation cast to bit
Previous Message Heikki Linnakangas 2007-11-20 21:42:57 Re: BUG #3765: strange results for bit string hex notation cast to bit