Re: BUG #8191: Wrong bit conversion

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #8191: Wrong bit conversion
Дата
Msg-id 14954.1370060858@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: BUG #8191: Wrong bit conversion  (Gerald Luger <GeraldLuger@hexboss.com>)
Список pgsql-bugs
Gerald Luger <GeraldLuger@hexboss.com> writes:
> Shouldn't I expect all results to be 000...0001?

Well, no.

The SQL spec is pretty clear about the interpretation of this:
    b'1'::bit(64)
You're taking a bit string of length 1 and casting it to bit string
of length 64.  That's done by appending zeroes on the right, per spec.

The x'1' notation isn't in SQL99 AFAICS, but we consider that x'1'
means the same as b'0001', and then the conversion from bit(4) to
bit(64) is done by padding zeroes on the right.

Your last case,
    1::bit(64)
represents casting an integer to bit(64).  This operation isn't in the
SQL spec either, unless I missed something.  We treat this as conversion
of the integer's twos-complement representation to a bit string,
presuming big-endian representation of the integer.

Now you can quibble with various of the details above, but in the end
they are all arbitrary decisions.  We've made them that way, and it
would take a pretty impressive argument to persuade us to break existing
applications by changing them.

            regards, tom lane

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

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: BUG #8191: Wrong bit conversion
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: BUG #8193: A few cosmetic misspell fixes.