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 [email protected]
Whole thread Raw
In response to Re: cannot cast type boolean to text?  (Tom Lane <[email protected]>)
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 < [email protected]> wrote:
Brian Hurt < [email protected]> 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: [email protected]
Date:
Subject: Formatting function, simple Q