Re: Boolean casting in 7.3 -> changed? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Boolean casting in 7.3 -> changed?
Date
Msg-id 28836.1038439122@sss.pgh.pa.us
Whole thread Raw
In response to Re: Boolean casting in 7.3 -> changed?  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: Boolean casting in 7.3 -> changed?  (Ian Barwick <barwick@gmx.net>)
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: [spam] Re: [mail] Re: Native Win32 sources
Next
From: Tom Lane
Date:
Subject: Planning for improved versions of IN/NOT IN