Skip site navigation (1) Skip section navigation (2)

Binary data type with other output method

From: Andreas 'ads' Scherbaum <adsmail(at)wars-nicht(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Binary data type with other output method
Date: 2007-12-25 10:33:03
Message-ID: 20071225113303.07760755@iridium.wars-nicht.de (view raw or flat)
Thread:
Lists: 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

Responses

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2007-12-25 16:10:25
Subject: Re: Binary data type with other output method
Previous:From: Bruce MomjianDate: 2007-12-25 06:16:10
Subject: Re: Spoofing as the postmaster

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group