Re: 'true'::TEXT::BOOLEAN

From: Markus Bertheau ☭ <twanger(at)bluetwanger(dot)de>
To: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Cc: PostgreSQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: 'true'::TEXT::BOOLEAN
Date: 2005-06-03 12:23:37
Message-ID: 1117801417.9816.28.camel@dicaprio.akademie1.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

This also bypasses the built in postgresql boolean literal parsing.

I think casting from text to boolean should be possible, and use the
same algorithm that's used when casting from "unknown" to boolean.

Markus

В Птн, 03/06/2005 в 21:14 +0900, Michael Glaesemann пишет:
> On Jun 3, 2005, at 8:52 PM, Markus Bertheau ☭ wrote:
>
> > And I can't call it with a TEXT variable, because casting from TEXT to
> > BOOLEAN isn't possible.
>
>
> I'd be surprised if there weren't a some way to coerce the cast from
> text to boolean, but you might want to just make a simple convenience
> function in the interim:
>
> test=# create or replace function text2bool (text)
> returns boolean language sql as $$
> select case
> when lower($1) = 'true'
> then true
> else false
> end;
> $$;
> CREATE FUNCTION
>
> test=# select text2bool('true');
> text2bool
> -----------
> t
> (1 row)
>
> test=# select text2bool('false');
> text2bool
> -----------
> f
> (1 row)
>
>
> Just an idea.
>
> Michael Glaesemann
> grzm myrealbox com
--
Markus Bertheau ☭ <twanger(at)bluetwanger(dot)de>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Glaesemann 2005-06-03 12:28:30 Re: 'true'::TEXT::BOOLEAN
Previous Message Michael Glaesemann 2005-06-03 12:14:18 Re: 'true'::TEXT::BOOLEAN