Lists: | pgsql-general |
---|
From: | "Willy-Bas Loos" <willybas(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Cast boolean to text |
Date: | 2006-12-07 09:08:50 |
Message-ID: | 1dd6057e0612070108j62cc1bb8j9a579e7de1791719@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
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".
From: | "Shoaib Mir" <shoaibmir(at)gmail(dot)com> |
---|---|
To: | "Willy-Bas Loos" <willybas(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Cast boolean to text |
Date: | 2006-12-07 09:44:30 |
Message-ID: | bf54be870612070144g1d9d6a2ct6b4ee7c9ec4eeeba@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
You can create a custome cast for this purpose that can convert bool to
text...
Regards,
Shoaib
On 12/7/06, Willy-Bas Loos <willybas(at)gmail(dot)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".
>
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Willy-Bas Loos" <willybas(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Cast boolean to text |
Date: | 2006-12-07 15:59:19 |
Message-ID: | 15657.1165507159@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
"Willy-Bas Loos" <willybas(at)gmail(dot)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
From: | "Shoaib Mir" <shoaibmir(at)gmail(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Willy-Bas Loos" <willybas(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Cast boolean to text |
Date: | 2006-12-08 05:07:31 |
Message-ID: | bf54be870612072107x587204f8u1d86046dc4270556@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
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
On 12/7/06, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> "Willy-Bas Loos" <willybas(at)gmail(dot)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
>