Re: An amusing MySQL weakness--not!

From: Darren Duncan <darren(at)darrenduncan(dot)net>
To: Michael Nolan <htfoot(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-26 07:05:58
Message-ID: 4E06DA56.8030905@darrenduncan.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Nolan wrote:
> Earlier today I was working on a MySQL database (not by choice, I assure
> you),
> and I typed a statement like this:
>
> Update tablexyz set field1 = '15' where field2 - 20;
>
> The '-' was supposed to be an equal sign, but MySQL executed it anyway.
> (Field2 is an integer.)
>
> I was not amused.
>
> PostgreSQL reports this as an error, of course.

I assume MySQL accepts this because it, like SQLite, doesn't have a real BOOLEAN
type and instead uses INTEGER for its truth values, I believe.

The result of any "foo = bar" is an INTEGER anyway, I believe, in such DBMSs,
same as "field2 - 20", and so if its result is nonzero, that is treated as TRUE.

Sure, that's inane, but for this one I would place a lot of blame on the SQL
standard, because it doesn't mandate BOOLEAN support, just making it optional,
and so lots of SQL DBMSs don't require BOOLEAN as the type of a WHERE expression.

Having real BOOLEAN is just one of the reasons I like Postgres the most.

-- Darren Duncan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vincent Veyron 2011-06-26 14:11:06 Re: An amusing MySQL weakness--not!
Previous Message Gavin Flower 2011-06-26 05:43:26 Re: An amusing MySQL weakness--not!