Search Postgresql Archives

Re: Constraint that compares and limits field values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 25, 2006 at 10:51:23AM -0800, MargaretGillon@xxxxxxxxxxxxxx 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux