Re: Shouldn't B'1' = 1::bit be true?

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Shouldn't B'1' = 1::bit be true?
Дата
Msg-id 20040309152612.F7528@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Shouldn't B'1' = 1::bit be true?  (Bill Moran <wmoran@potentialtech.com>)
Список pgsql-general
On Wed, 3 Mar 2004, Bill Moran wrote:

> Am I missing something here?
>
> agelis=# select B'1'::int;
>   int4
> ------
>      1
> (1 row)
>
> agelis=# select 1::bit;
>   bit
> -----
>   0
> (1 row)
>
> agelis=# select B'1'=1;
>   ?column?
> ----------
>   f
> (1 row)
>
> Last I checked, binary 1 and integer 1 were equal.  Is this a bug, or is there
> a reason for this that I need educated on?  Why does int 1 cast to binary 0?

Hmm, on my 7.4 machine, I get an error saying that there's no = operator
for bit and integer.  If I cast the B'1' into an integer I get a true
result.

The reason for 1::bit being 0 is that int4 -> bit(n) casts cast to a 32
bit bit string.  IIRC, when bit strings are truncated for size in casts,
the spec says to take from the left.



В списке pgsql-general по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: How do I change column details
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: C locale