Re: Casting to varchar

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Scott Ribe <scott_ribe(at)killerbytes(dot)com>
Cc: Postgresql General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Casting to varchar
Date: 2007-05-04 20:42:07
Message-ID: 463B9A9F.80008@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/05/2007 21:34, Scott Ribe wrote:

> Just discovered (the hard way) that casting a boolean column ::varchar
> doesn't work. I assume I can add a function somewhere that will define a
> default cast for this? Are there any other standard types that can't be cast

I just use something like this:

create or replace function bool2str(TheValue boolean)
returns varchar as
$$
begin
if TheValue then
return 'true';
else
return 'false';
end if;
end;
$$
language plpgsql stable;

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
---------------------------------------------------------------

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-05-04 20:46:37 Re: Casting to varchar
Previous Message Scott Ribe 2007-05-04 20:34:24 Casting to varchar