Extending a bit string

From: Evan Carroll <me(at)evancarroll(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Extending a bit string
Date: 2018-04-24 05:32:37
Message-ID: CAAiePB4JimamXK1S87eZ6R7BMq8OFOwuMgOfJkCL8YFus_YAVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)evancarroll(dot)com
System Lord of the Internets
web: http://www.evancarroll.com
ph: 281.901.0011

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gasper Zejn 2018-04-24 05:41:34 Re: community bonding
Previous Message Andrey Borodin 2018-04-24 05:04:22 Re: [HACKERS] Clock with Adaptive Replacement