Cast boolean to text

Started by Willy-Bas Loosover 19 years ago4 messagesgeneral
Jump to latest
#1Willy-Bas Loos
willybas@gmail.com

Hi,

I've noticed that postgresql 8.1.0 can cast a boolean to text, but version
8.1.5 CAN'T.
Is this a bug or a feature?

as proof, try to run this query:
select 't'::bool::text

On version 8.1.5 one will recieve the error message "can't convert boolean
to text".

#2Shoaib Mir
shoaibmir@gmail.com
In reply to: Willy-Bas Loos (#1)
Re: Cast boolean to text

You can create a custome cast for this purpose that can convert bool to
text...

Regards,
Shoaib

Show quoted text

On 12/7/06, Willy-Bas Loos <willybas@gmail.com> wrote:

Hi,

I've noticed that postgresql 8.1.0 can cast a boolean to text, but
version 8.1.5 CAN'T.
Is this a bug or a feature?

as proof, try to run this query:
select 't'::bool::text

On version 8.1.5 one will recieve the error message "can't convert boolean
to text".

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Willy-Bas Loos (#1)
Re: Cast boolean to text

"Willy-Bas Loos" <willybas@gmail.com> writes:

I've noticed that postgresql 8.1.0 can cast a boolean to text, but version
8.1.5 CAN'T.

Better check again --- there has never been a standard cast from bool to
text. Sure you didn't install a custom one in your 8.1.0 database?

regards, tom lane

#4Shoaib Mir
shoaibmir@gmail.com
In reply to: Tom Lane (#3)
Re: Cast boolean to text

You can create a cast like this:

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

create cast (boolean as char(1))
with function bool_to_text(boolean)
as implicit;
*
Thank you,
Shoaib

Show quoted text

On 12/7/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:

"Willy-Bas Loos" <willybas@gmail.com> writes:

I've noticed that postgresql 8.1.0 can cast a boolean to text, but

version

8.1.5 CAN'T.

Better check again --- there has never been a standard cast from bool to
text. Sure you didn't install a custom one in your 8.1.0 database?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend