Extending a bit string - Mailing list pgsql-hackers

From Evan Carroll
Subject Extending a bit string
Date
Msg-id CAAiePB4JimamXK1S87eZ6R7BMq8OFOwuMgOfJkCL8YFus_YAVw@mail.gmail.com
Whole thread Raw
Responses Re: Extending a bit string
List pgsql-hackers
Currently the behavior of bit-string extensions is pretty insane.

SELECT b'01'::bit(2)::bit(4),
  b'01'::bit(2)::int::bit(4);
 bit  | bit  
------+------
 0100 | 0001
(1 row)

I'd like propose we standardize this a bit. Previously, in version 8 compatibility was broke. From the Version 8 release notes (thanks to Rhodium Toad for the research),

> Casting an integer to BIT(N) selects the rightmost N bits of the integer, not the leftmost N bits as before.

Everything should select the right-most bits, and extend the left-most bits from the docs:

> Casting an integer to a bit string width wider than the integer itself will sign-extend on the left.

That makes sense to me. Intergers sign-extend on the left, and the behavior is currently undefined for bit->bit extensions. What say you?

--
Evan Carroll - me@evancarroll.com
System Lord of the Internets
web: http://www.evancarroll.com
ph: 281.901.0011

pgsql-hackers by date:

Previous
From: Andrey Borodin
Date:
Subject: Re: [HACKERS] Clock with Adaptive Replacement
Next
From: Gasper Zejn
Date:
Subject: Re: community bonding