Re: ALTER TABLE ( smallinto -> boolean ) ...

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER TABLE ( smallinto -> boolean ) ...
Date: 2005-09-01 21:23:08
Message-ID: 4317713C.10808@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Tom Lane wrote:

>"Marc G. Fournier" <scrappy(at)postgresql(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-09-01 21:25:28 Re: [HACKERS] ALTER TABLE ( smallinto -> boolean ) ...
Previous Message Tom Lane 2005-09-01 21:16:48 Re: rename constraint behavior for duplicate names?

Browse pgsql-sql by date

  From Date Subject
Next Message Owen Jacobson 2005-09-01 21:24:59 Re: [HACKERS] ALTER TABLE ( smallinto -> boolean ) ...
Previous Message Marc G. Fournier 2005-09-01 21:15:25 Re: [HACKERS] ALTER TABLE ( smallinto -> boolean ) ...