On Thursday 28 November 2002 00:18, Tom Lane wrote: > Peter Eisentraut <[EMAIL PROTECTED]> 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 have a boolean data type, but the values 0 and 1 in scalar context do the job just as well; - MySQL happily accepts literals for 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 or cast the expression" - so I did what it said and wrote 0::bool - and thought no further of it, until now when I began the upgrade. - being in a bit of a hurry I put tried '0'::bool and it worked... - having rtfm, obviously just '0' and no mucking about with casting is better anyway... Peter Eisentraut <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster