![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
The following bug has been logged online: Bug reference: 1578 Logged by: Celia McInnis Email address: celia (AT) drmath (DOT) ca PostgreSQL version: 8.0.1 Operating system: Linux Description: ::bit(n) behaves "differently" if applied to bit strings than integers. Details: It's probably not good (at least for mathematicians!) to have the following give different results: select B'1110110101'::bit(6); select B'1110110101'::integer::bit(6); The first gives 110101 (the 6 least significant bits). The second gives 111011 (the 6 most significant bis). |
#2
| |||
| |||
|
|
... Though this is slightly inconsistent in how it works with a bit string, it does seem the most useful approach. |
#3
| |||
| |||
|
|
select 949::bit(10) gives 1110110101 (as expected). select 949::bit(10)::bit(3) gives 111 (the 3 most significant bits) select 949::bit(3) gives 101 (the 3 least significant bits). As a mathematician, I'd certainly at least want the last two selects to give the same results! |
#4
| |||
| |||
|
|
Bruce Momjian <pgman (AT) candle (DOT) pha.pa.us> writes: ... Though this is slightly inconsistent in how it works with a bit string, it does seem the most useful approach. Also, this is a behavior that we changed in 8.0 in response to previous complaints. Before changing it again, I'd want to see a pretty detailed analysis of either (1) why the previous complainers were idiots, or (2) why this change is still compatible with what they asked for ;-) Where relevant, comments on SQL spec compliance would help the argument too. I don't think the spec defines any bit<->integer conversions, but it definitely addresses the issue of converting from bit(m) to bit(n). regards, tom lane |
#5
| |||
| |||
|
|
Celia McInnis <celia (AT) drmath (DOT) ca> wrote: 949 base 10 = 1110110101 base two. select 949::bit(10) gives 1110110101 (as expected). |
|
Why is that expected? Based on your reasoning for the last case I would expect '0000000000', since the first 10 bits of that integer are 0. |
|
select 949::bit(10)::bit(3) gives 111 (the 3 most significant bits) select 949::bit(3) gives 101 (the 3 least significant bits). As a mathematician, I'd certainly at least want the last two selects to give the same results! |
![]() |
| Thread Tools | |
| Display Modes | |
| |