Re: Constraint that compares and limits field values - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Constraint that compares and limits field values
Date
Msg-id 20060125185814.GA77056@winnie.fuhr.org
Whole thread Raw
In response to Re: Constraint that compares and limits field values  (MargaretGillon@chromalloy.com)
List pgsql-general
On Wed, Jan 25, 2006 at 10:51:23AM -0800, MargaretGillon@chromalloy.com wrote:
> I am in version 7.3 and it will not let me cast, I get message "ERROR:
> Cannot cast type boolean to integer". I will save this for when I upgrade.

You can create casts with CREATE CAST.

http://www.postgresql.org/docs/7.3/static/sql-createcast.html

Something like this should work:

CREATE FUNCTION bool2int(boolean) RETURNS integer AS '
SELECT CASE WHEN $1 THEN 1 ELSE 0 END;
' LANGUAGE sql IMMUTABLE STRICT;

CREATE CAST (boolean AS integer) WITH FUNCTION bool2int(boolean);

--
Michael Fuhr

pgsql-general by date:

Previous
From: MargaretGillon@chromalloy.com
Date:
Subject: Re: Constraint that compares and limits field values
Next
From: Benjamin Smith
Date:
Subject: Re: Postgresql Segfault in 8.1