Skip site navigation (1) Skip section navigation (2)

Re: BUG #1135: integer::bit returns incorrect results

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: (view raw, whole thread or download thread mbox)
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;
(1 row)
regression=# select (255)::bit(32);
(1 row)
regression=# select (-255)::bit(32);
(1 row)
regression=# select (-255)::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

In response to

pgsql-bugs by date

Next:From: PostgreSQL Bugs ListDate: 2004-04-19 17:13:50
Subject: BUG #1136: Error finding columns with mixed case names
Previous:From: eleinDate: 2004-04-18 19:40:26
Subject: Re: BUG #1135: integer::bit returns incorrect results

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group