From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "elein" <elein(at)varlena(dot)com> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #1135: integer::bit returns incorrect results |
Date: | 2004-04-18 22:00:38 |
Message-ID: | 11507.1082325638@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> These all return 0.
> select 1::bit;
> select 2::bit;
> select 111::bit;
> select 101::bit;
"bit" means "bit(1)" per SQL spec, so only the first of these could
possibly act as you're expecting anyway.
The reason none of them do is that the coercion function actually yields
bit(32), with the MSB of the integer at the left, and then coercion to
bit(1) drops all but the sign bit. So for example
regression=# select (255)::bit;
bit
-----
0
(1 row)
regression=# select (255)::bit(32);
bit
----------------------------------
00000000000000000000000011111111
(1 row)
regression=# select (-255)::bit(32);
bit
----------------------------------
11111111111111111111111100000001
(1 row)
regression=# select (-255)::bit(1);
bit
-----
1
(1 row)
There was previous discussion of this a month or so ago, but nobody
could come up with a reasonable definition that didn't have large
implementability or backwards-compatibility issues ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | PostgreSQL Bugs List | 2004-04-19 17:13:50 | BUG #1136: Error finding columns with mixed case names |
Previous Message | elein | 2004-04-18 19:40:26 | Re: BUG #1135: integer::bit returns incorrect results |