Chris K-L's recent complaint reminded me that we had been talking about
redefining int-to-bit(n) casting to take the rightmost n bits of the
integer value, instead of the leftmost n bits.  The implementation
reason why it works the way it does is that the existing cast function
effectively converts to bit(32), and then after that we cast to bit(n),
and the bitstring width-conversion transformation takes the leftmost
bits of the bitstring, which is per SQL spec.

The only convenient way I can see to handle this is to extend the cast
stuff so that the cast function can be passed an additional parameter
which is the target typmod.  Armed with that info, inttobit() could
align its output bits properly for the upcoming bitstring truncation.

Now that cast functions are selected through pg_cast, this should be a
fairly straightforward change.  Does anyone have a problem with it?
I'm not sure the functionality is actually useful for anything except
this one issue, but arguably it's a general-purpose mechanism...

			regards, tom lane

Mon, 14 Jun 2004 09:35:14 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Passing typmod to cast functions (for int-to-bit casting)
> Now that cast functions are selected through pg_cast, this should be a
> fairly straightforward change.  Does anyone have a problem with it?
> I'm not sure the functionality is actually useful for anything except
> this one issue, but arguably it's a general-purpose mechanism...

Does that help with making CREATE TABLE AS SELECT pick up varchar 
lengths, etc.?

Chris


Tue, 15 Jun 2004 09:38:05 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Re: Passing typmod to cast functions (for int-to-bit casting)
Christopher Kings-Lynne <chriskl@familyhealth.com.au> writes:
> Does that help with making CREATE TABLE AS SELECT pick up varchar 
> lengths, etc.?

Not any better than it does now, no ... but AFAIK simple cases work okay
on that.  What's your gripe exactly?

			regards, tom lane

Mon, 14 Jun 2004 22:52:07 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Passing typmod to cast functions (for int-to-bit casting) 
> Not any better than it does now, no ... but AFAIK simple cases work okay
> on that.  What's your gripe exactly?

No gripe - was just pointing out a situation that might be improved 
slightly be carrying around typmod info.

Chris


Tue, 15 Jun 2004 11:15:51 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Re: Passing typmod to cast functions (for int-to-bit casting)