On Aug 31, 2004, at 6:06 PM, sad wrote:

why BOOL can not be casted to TEXT
....nevertheless BOOL has a textual (output) representation 't' and 'f' letters
why not to use this fact to define cast to TEXT ?

I'm not sure of the reason why there isn't a built-in cast from boolean to text, though I'm not a big fan of casts in general so it doesn't really bother me too much. If this is something you desire, I believe you can use CREATE CAST to make your own cast from boolean to text.


test=# select true::text;
ERROR:  cannot cast type boolean to text

create or replace function bool_to_text (boolean)
    returns text
    strict
    language sql as '
    select case
        when $1 then \'t\'
        else \'f\'
        end;
    ';

create cast (boolean as text)
    with function bool_to_text(boolean)
    as assignment;

test=# select true::text;
 text
------
 t
(1 row)

You can find more information at
<http://www.postgresql.org/docs/current/static/sql-createcast.html>

Hope this helps!

Michael Glaesemann
grzm myrealbox com


---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply via email to