Tom Lane wrote:
>"Marc G. Fournier" <scrappy@postgresql.org> writes:
>
>
>>On Mon, 29 Aug 2005, Tom Lane wrote:
>>
>>
>>>No, because there's no built-in cast from smallint to bool.
>>>
>>>
>
>
>
>>'k, I just took a read through the "CREATE CAST" man page, and don't think
>>I can use that for this,
>>
>>
>
>Sure you can. Make a SQL or PLPGSQL function that does the conversion
>you want and then create a cast using it.
>
>
That probably won't help him much with "values(0)":
andrew=# create function ibool(smallint) returns boolean language sql as
$$ select $1 <> 0 $$;
CREATE FUNCTION
andrew=# create cast (smallint as boolean) with function ibool(smallint)
as implicit;
CREATE CAST
andrew=# insert into foobool values(0);
ERROR: column "x" is of type boolean but expression is of type integer
HINT: You will need to rewrite or cast the expression.
Is there a way to make the builtin int to bool cast implicit?
cheers
andrew