Re: casting BOOL to somthng - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: casting BOOL to somthng
Date
Msg-id 4B1E87BC-FB36-11D8-A2A0-000A95C88220@myrealbox.com
Whole thread Raw
In response to casting BOOL to somthng  (sad <sad@bankir.ru>)
Responses Re: casting BOOL to somthng  (sad <sad@bankir.ru>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: sad
Date:
Subject: casting BOOL to somthng
Next
From: Martin Marques
Date:
Subject: colored PL with emacs