Re: cannot cast type boolean to text? - Mailing list pgsql-novice

From Shoaib Mir
Subject Re: cannot cast type boolean to text?
Date
Msg-id bf54be870706141143m7939f764sb829da2a14e038bd@mail.gmail.com
Whole thread Raw
In response to Re: cannot cast type boolean to text?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
This should help:

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;

--
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 6/14/07, Tom Lane < tgl@sss.pgh.pa.us> wrote:
Brian Hurt < bhurt@janestcapital.com> writes:
>     SELECT true :: text;
> ERROR:  cannot cast type boolean to text

> I was wondering why this is so.

Because there's no pg_cast entry for this conversion.

There will be one in 8.3, but for older releases make your own with
CREATE CAST.

                        regards, tom lane

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

               http://archives.postgresql.org

pgsql-novice by date:

Previous
From: "Shoaib Mir"
Date:
Subject: Re: cannot cast type boolean to text?
Next
From: nhrcommu@rochester.rr.com
Date:
Subject: Formatting function, simple Q