Peter Eisentraut <peter_e@gmx.net> writes:
> Ian Barwick writes:
>> "Casting integers to boolean (for example, 0::bool) is no longer allowed,
>> use '0'::bool instead".
> This advice would probably only cause more confusion, because we are now
> moving into the direction that character strings are no longer acceptable
> as numeric data.
Yes, phrased that way it's just misleading. We do not and did not have
a general int-to-bool cast (though it may be reasonable to add one, now
that we could mark it explicit-only). The case that worked in 7.2 and
before was only for numeric-looking *literals* being cast to bool (or
any other type for that matter) --- parser_typecast_constant would
essentially act as though the literal had quotes around it, whether
it actually did or not. Thus in the old code, the validity of, say,42::bool
would depend on whether bool's input converter would accept the string
'42'. In the new code, 42 is taken to be an int4 constant and the
validity of the expression depends on whether there is an int4-to-bool
cast.
7.2:
regression=# select 42::bool;
ERROR: Bad boolean external representation '42'
Current:
regression=# select 42::bool;
ERROR: Cannot cast type integer to boolean
regards, tom lane