confused about bit strings

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: confused about bit strings
Date: 2003-10-08 17:38:53
Message-ID: 1065634733.3423.21.camel@tokyo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Is the following behavior intentional? If so, what's the reasoning
behind it?

nconway=# select 1::bit;
bit
-----
0
(1 row)
nconway=# select '1'::bit;
bit
-----
1
(1 row)
nconway=# select X'1'::bit;
bit
-----
0
(1 row)
nconway=# select 1::bit varying;
ERROR: cannot cast type integer to bit varying
nconway=# select 4::int2::bit;
ERROR: cannot cast type smallint to bit

nconway=# select 4::bit;
bit
-----
0
(1 row)
nconway=# select '4'::bit;
ERROR: "4" is not a valid binary digit
nconway=# select X'4'::bit varying;
varbit
--------
0100
(1 row)
-- why is that 4 bits, not 3?

nconway=# select '14'::int::bit;
bit
-----
0
(1 row)
nconway=# select bit('14'::int);
ERROR: syntax error at or near "'14'" at character 12
nconway=# select "bit"('14'::int);
bit
----------------------------------
00000000000000000000000000001110
(1 row)
-- shouldn't bit be equivalent to bit(1), which should be
right-truncated?

Cheers,

Neil

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2003-10-08 17:43:31 Re: Sun performance - Major discovery!
Previous Message Peter Eisentraut 2003-10-08 17:38:30 Re: setlocale