Re: Extending a bit string

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Evan Carroll <me(at)evancarroll(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Extending a bit string
Date: 2018-04-24 14:41:22
Message-ID: 23528.1524580882@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Evan Carroll <me(at)evancarroll(dot)com> writes:
> Currently the behavior of bit-string extensions is pretty insane.

You've provided no support for this assertion, much less any defense
of why your proposed semantics change is any less insane. Also, if
I understood you correctly, you want to change the semantics of
casting a bitstring to a bitstring of a different length, which is
an operation that's defined by the SQL standard. You will get zero
traction on that unless you convince people that we've misread the
standard. Which is possible, but the text seems clear to me that
casting bit(2) to bit(4) requires addition of zeroes on the right:

11) If TD is fixed-length bit string, then let LTD be the length in
bits of TD. Let BLSV be the result of BIT_LENGTH(SV).
...
c) If BLSV is smaller than LTD, then TV is SV expressed as a
bit string extended on the right with LTD-BLSV bits whose
values are all 0 (zero) and a completion condition is raised:
warning - implicit zero-bit padding.

That's SQL:99 6.22 <cast specification> general rule 11) c).
(SV and TD are the source value and the target datatype for a cast.)

In hindsight, it would likely be more consistent with this if we'd
considered bitstrings to be LSB first when coercing them to/from integer,
but whoever stuck that behavior in didn't think about it. Too late to
change that now I'm afraid, though perhaps we could provide non-cast
conversion functions that act that way.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2018-04-24 15:16:33 Re: Bugs in TOAST handling, OID assignment and redo recovery
Previous Message Adam Brusselback 2018-04-24 14:28:11 Re: Built-in connection pooling