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

From Andreas 'ads' Scherbaum
Subject Binary data type with other output method
Date
Msg-id 20071225113303.07760755@iridium.wars-nicht.de
Whole thread Raw
Responses Re: Binary data type with other output method
List pgsql-hackers
Hello all,

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.

And so i asked myself, if there is an easier way than my current
approach. Right now i'm creating input/output functions, the datatype
and a lot of casts and operators (350 lines SQL) just to get another
output:

CREATE FUNCTION boolean2_in(cstring)  RETURNS boolean2  AS 'boolin'  LANGUAGE internal STRICT;
CREATE FUNCTION boolean2_out(boolean2)  RETURNS cstring  AS 'int2out'  LANGUAGE internal STRICT;
CREATE FUNCTION boolean2_recv(internal)  RETURNS boolean2  AS 'boolrecv'  LANGUAGE internal STRICT;
CREATE FUNCTION boolean2_send(boolean2)  RETURNS bytea  AS 'boolsend'  LANGUAGE internal STRICT;

CREATE TYPE boolean2 (  input = boolean2_in,  output = boolean2_out,  receive = boolean2_recv,  send = boolean2_send,
internallength= 1,  alignment = char,  storage = plain,  passedbyvalue
 
);

CREATE CAST (boolean2 AS boolean)   WITHOUT FUNCTION        AS ASSIGNMENT;
CREATE CAST (boolean AS boolean2)   WITHOUT FUNCTION        AS ASSIGNMENT;

... and so on.


Can i have this in an easier way?


Kind regards

--             Andreas 'ads' Scherbaum
German PostgreSQL User Group


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Spoofing as the postmaster
Next
From: Andrew Dunstan
Date:
Subject: Re: Binary data type with other output method