From: | Ian Barwick <barwick(at)gmx(dot)net> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Boolean casting in 7.3 -> changed? |
Date: | 2002-11-28 18:45:21 |
Message-ID: | 200211281945.21587.barwick@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thursday 28 November 2002 00:18, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)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 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 <peter_e(at)gmx(dot)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(at)gmx(dot)net
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2002-11-28 20:16:20 | [GENERAL] PostgreSQL Global Development Group Announces Version 7.3 (fwd) |
Previous Message | Andrew J. Kopciuch | 2002-11-28 18:17:13 | Re: System Tables |