Re: Constraint that compares and limits field values

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: MargaretGillon(at)chromalloy(dot)com
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Constraint that compares and limits field values
Date: 2006-01-25 18:58:14
Message-ID: 20060125185814.GA77056@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jan 25, 2006 at 10:51:23AM -0800, MargaretGillon(at)chromalloy(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Benjamin Smith 2006-01-25 19:04:34 Re: Postgresql Segfault in 8.1
Previous Message MargaretGillon 2006-01-25 18:52:55 Re: Constraint that compares and limits field values