X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F2B7652802 for ; Fri, 3 Jun 2005 09:23:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40507-08 for ; Fri, 3 Jun 2005 12:23:43 +0000 (GMT) Received: from web11.manitu.net (web11.manitu.net [217.11.48.111]) by svr1.postgresql.org (Postfix) with ESMTP id 365F252896 for ; Fri, 3 Jun 2005 09:23:42 -0300 (ADT) Received: from dicaprio.akademie1.de (dicaprio.akademie1.de [62.165.4.166]) (authenticated) by web11.manitu.net (8.10.2-SOL3/8.10.2) with ESMTP id j53CNgT20299; Fri, 3 Jun 2005 14:23:42 +0200 Subject: Re: 'true'::TEXT::BOOLEAN From: Markus Bertheau =?UTF-8?Q?=E2=98=AD?= To: Michael Glaesemann Cc: PostgreSQL In-Reply-To: <3DCEDE55-9D4A-4F4E-8907-ADCC058A3398@myrealbox.com> References: <1117799555.9816.24.camel@dicaprio.akademie1.de> <3DCEDE55-9D4A-4F4E-8907-ADCC058A3398@myrealbox.com> Content-Type: text/plain; charset=utf-8 Date: Fri, 03 Jun 2005 14:23:37 +0200 Message-Id: <1117801417.9816.28.camel@dicaprio.akademie1.de> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 (2.0.4-4) Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.019 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/41 X-Sequence-Number: 21642 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 ☭