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

BUG #1135: integer::bit returns incorrect results

From: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1135: integer::bit returns incorrect results
Date: 2004-04-18 19:04:08
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
The following bug has been logged online:

Bug reference:      1135
Logged by:          elein

Email address:      elein(at)varlena(dot)com

PostgreSQL version: 7.4

Operating system:   SuSE

Description:        integer::bit returns incorrect results


* There exists a cast utils/adt.c/bitfromint4()
  in pg_casts listed to cast an integer to a bit.

  This cast seems to always set the value to 0.
  On cursory glance bitfromint4 seems right, but
  the shortcut shifting could be wrong. (Why isn't
  just the low bit set?).

  If I have time, I'll look more carefully, and
  perhaps submit a patch unless someone gets to
  it before I do.

* There is no cast from an integer to a bit varying.

  If there exists a cast from integer to bit (in question :-)
  there should be one from integer to bit varying.
  It should be a straight copy.

These all return 0.
   select 1::bit;
   select 2::bit;
   select 111::bit;
   select 101::bit;

elein=# select 1::bit varying;
ERROR:  cannot cast type integer to bit varying

Side note: the text string cast to bit and bit varying
works fine and the digits are limited to 1s and 0s.
But that should not be how integer to bit/bit varying should

elein=# select '101'::bit;
(1 row)

elein=# select '2'::bit;
ERROR:  "2" is not a valid binary digit


pgsql-bugs by date

Next:From: eleinDate: 2004-04-18 19:40:26
Subject: Re: BUG #1135: integer::bit returns incorrect results
Previous:From: Andreas PflugDate: 2004-04-18 10:50:51
Subject: Re: [7.4.2] Still "variable not found in subplan target lists"

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