Re: Binary data type with other output method - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: Binary data type with other output method
Date
Msg-id 47718F19.1070908@dunslane.net
Whole thread Raw
In response to Re: Binary data type with other output method  (Andreas 'ads' Scherbaum <adsmail@wars-nicht.de>)
Responses Re: Binary data type with other output method  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

Andreas 'ads' Scherbaum wrote:
> Hello,
>
> On Tue, 25 Dec 2007 11:10:25 -0500 Andrew Dunstan wrote:
>
>   
>> Andreas 'ads' Scherbaum wrote:
>>     
>>> i'm in the need to create a boolean datatype which returns an integer
>>> instead of the usual 't'/'f'. Before anyone starts to point me at
>>> casts: it's a lot overhead to cast some hundred occurances beside the
>>> source of trouble, if you forget one.
>>>   
>>>       
>> Do you really need a new datatype or just to change the output behaviour 
>> of the inbuilt type? That should be quite easy to do in just a few lines 
>> of code.
>>     
>
> Just another output behavior would be enough ... but without changing
> the PG source itself. Since the package comes with the distribution,
> there's no way to build PG from source.
>
>
>
>   

I think all you need to do it this:

Take the code for boolout() in src/backend/utils/adt/bool.c, adjust it 
and and make it a new function boolout2. Use pgxs to make it a loadable 
module.

Then load it and adjust the catalog entry for the bool type to use 
boolout2 instead of boolout.

Caveat: I think you would need to redo the type adjustment after every 
restore, as it wouldn't be dumped.

cheers

andrew


pgsql-hackers by date:

Previous
From: Andreas 'ads' Scherbaum
Date:
Subject: Re: Binary data type with other output method
Next
From: Tom Lane
Date:
Subject: Re: Binary data type with other output method