pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Converting varchar to bool
2+ messages / 2 participants
[nested] [flat]

* Converting varchar to bool
@ 2005-06-15 12:14  KÖPFERL Robert <robert.koepferl@sonorys.at>
  0 siblings, 1 reply; 2+ messages in thread

From: KÖPFERL Robert @ 2005-06-15 12:14 UTC (permalink / raw)
  To: ; +Cc: pgsql-sql

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??

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.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Converting varchar to bool
@ 2005-06-15 14:31  Bruno Wolff III <bruno@wolff.to>
  parent: KÖPFERL Robert <robert.koepferl@sonorys.at>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruno Wolff III @ 2005-06-15 14:31 UTC (permalink / raw)
  To: KÖPFERL Robert <robert.koepferl@sonorys.at>; +Cc: pgsql-sql

On Wed, Jun 15, 2005 at 14:14:46 +0200,
  KÖPFERL Robert <robert.koepferl@sonorys.at> 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)




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-06-15 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-15 12:14 Converting varchar to bool KÖPFERL Robert <robert.koepferl@sonorys.at>
2005-06-15 14:31 ` Bruno Wolff III <bruno@wolff.to>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox