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 128D75283D for ; Wed, 15 Jun 2005 11:31:58 -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 13095-02 for ; Wed, 15 Jun 2005 14:31:50 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 9A48852823 for ; Wed, 15 Jun 2005 11:31:48 -0300 (ADT) Received: (qmail 8491 invoked by uid 500); 15 Jun 2005 14:31:24 -0000 Date: Wed, 15 Jun 2005 09:31:24 -0500 From: Bruno Wolff III To: =?iso-8859-1?Q?K=D6PFERL?= Robert Cc: Sql-Postgre Subject: Re: Converting varchar to bool Message-ID: <20050615143124.GC7595@wolff.to> Mail-Followup-To: Bruno Wolff III , =?iso-8859-1?Q?K=D6PFERL?= Robert , Sql-Postgre References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/171 X-Sequence-Number: 21772 On Wed, Jun 15, 2005 at 14:14:46 +0200, KÖPFERL Robert wrote: > Hi, > > > I have currently trouble working with boolean values and variables in > functions. > > As one would expect, a > select '1'::bool, 't'::bool, 'true'::unknown::boolean > > works. > > As a select '1' tells us this seems as a conversion unknown->bool > or ??maybe?? a boolean literal?? No it is not a conversion, '1', 't' and 'true' are all valid boolean strings representing TRUE. The input is not being converted from text to boolean. > > what-o-ever, at least my function gets not accepted: > > > CREATE OR REPLACE FUNCTION testbool(varchar) > RETURNS boolean AS > $BODY$ > SELECT $1::boolean > $BODY$ > LANGUAGE 'sql' STABLE STRICT SECURITY DEFINER; > > Postgres complains that it can't convert varchar to boolean. > Actually neither $1::unknown::bool works. > It turns out that there exists no conversion varchar/text/unknown -> > boolean. > Actually there's not any conversion -> boolean. > > How should this be treaten? > *being confused* > > > sorry for duplicating (I'm sure) this topic, at least I tried to find it in > the listarcive. It has been discussed in the last week. test.sql: CREATE OR REPLACE FUNCTION testbool(varchar) RETURNS boolean AS $BODY$ SELECT boolin(textout($1)); $BODY$ LANGUAGE 'sql' STABLE STRICT SECURITY DEFINER; SELECT testbool('true'); bruno=> \i test.sql CREATE FUNCTION testbool ---------- t (1 row)