From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | sad <sad(at)bankir(dot)ru> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: casting BOOL to somthng |
Date: | 2004-08-31 10:12:41 |
Message-ID: | 4B1E87BC-FB36-11D8-A2A0-000A95C88220@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | sad | 2004-08-31 11:24:16 | Re: casting BOOL to somthng |
Previous Message | sad | 2004-08-31 09:06:25 | casting BOOL to somthng |