Re: Boolean casting in 7.3 -> changed?

Поиск
Список
Период
Сортировка
От Ian Barwick
Тема Re: Boolean casting in 7.3 -> changed?
Дата
Msg-id 200211281945.21587.barwick@gmx.net
обсуждение исходный текст
Ответ на Re: Boolean casting in 7.3 -> changed?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Thursday 28 November 2002 00:18, Tom Lane wrote:
> 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.

OK, what I am trying to say is something like:

"If you are upgrading an application to PostgreSQL 7.3
and are having problems with boolean casts which look like
0::bool or 1::bool, which previously worked without any problem,
(although not explicitly supported) you will need to rewrite them
to use the values listed here:

http://www.postgresql.org/idocs/index.php?datatype-boolean.html .

Doing things like '0'::bool will also work but is not recommended."

because that's a problem I came across but found no mention of,
so I thought I would point it out for the benefit of anyone else
who might encounter it ;-)

For reference, the reason why I was casting integer-like literals
to boolean in the first place is: - Perl application used to run on a combination of MySQL and Oracle;- Perl doesn't
havea boolean data type, but the values 0 and 1  in scalar context do the job just as well;- MySQL happily accepts
literalsfor boolean column types,  e.g. INSERT INTO table_with_boolean_column                    (boolean_column)
     VALUES (0)- the same statement in PostgreSQL produced
 
"ERROR:  Attribute 'boolean_column' is of type 'bool' but expression is of type 'int4'        You will need to rewrite
orcast the expression"- so I did what it said and wrote 0::bool -  and thought  no further of it, until now when I
beganthe upgrade.- being in a bit of a hurry I put tried '0'::bool and it worked...- having rtfm, obviously just '0'
andno mucking about with casting  is better anyway...
 

Peter Eisentraut <peter_e@gmx.net> wrote:
> Note that
>
> x <> 0
>
> is also a perfectly good way to convert integers to booleans, and a more
> portable one at that.

Ah, that is a useful tip. 

Thanks for the information

Ian Barwick
barwick@gmx.net



В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Andrew J. Kopciuch"
Дата:
Сообщение: Re: System Tables
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: nested transactions