Re: boolean to int - Mailing list pgsql-general

From Pavel Stehule
Subject Re: boolean to int
Date
Msg-id Pine.LNX.4.44.0403151957590.26812-100000@kix.fsv.cvut.cz
Whole thread Raw
In response to boolean to int  (Mage <mage@mage.hu>)
Responses Re: boolean to int
Re: boolean to int
List pgsql-general
Hello, you can use own cast.

create or replace function int2bool (integer) returns boolean as '
  select case when $1=1 then ''t''::boolean else ''f''::boolean end;
' language sql;

create or replace function bool2int (boolean) returns integer as '
  select case when $1 then 0 else 1 end; ' language sql;

create cast (integer as boolean) with function int2bool(integer)
  as implicit;

create cast (boolean as integer) with function bool2int(boolean)
  as implicit;

regards
Pavel Stehule


On Mon, 15 Mar 2004, Mage wrote:

>        Hello,
>
> I'm wondering why pgsql doesn't support boolean typecasts like select
> true::int;
> Many client applications including php assign 1 to true and 0 to false
>
> I see no use of pgsql boolean type with php, I use int2 or integer.
>
>        Mage
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


pgsql-general by date:

Previous
From: Steve Crawford
Date:
Subject: Re: returning row numbers in select
Next
From: Richard Huxton
Date:
Subject: Re: PostgeSQL problem (server crashed?)