Re: An amusing MySQL weakness--not!

Lists: pgsql-general
From: Michael Nolan <htfoot(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: An amusing MySQL weakness--not!
Date: 2011-06-26 04:44:49
Message-ID: BANLkTikAj1YO7Vzz5wYpLt5PvodbSwF6nw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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.
--
Mike Nolan
nolan(at)tssi(dot)com


From: merlyn(at)stonehenge(dot)com (Randal L(dot) Schwartz)
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 04:53:41
Message-ID: 86oc1lkxbe.fsf@red.stonehenge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

>>>>> "Michael" == Michael Nolan <htfoot(at)gmail(dot)com> writes:

Michael> Earlier today I was working on a MySQL database (not by choice, I assure
Michael> you),

Friends don't let friends use MySQL.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(at)stonehenge(dot)com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
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 05:43:26
Message-ID: 4E06C6FE.8060701@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 26/06/11 16:44, 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.
> --
> Mike Nolan
> nolan(at)tssi(dot)com <mailto:nolan(at)tssi(dot)com>

I am guessing that '(field2 - 20)' is evaluated, and if non-zero it is
treated as true?


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
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


From: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
To: Darren Duncan <darren(at)darrenduncan(dot)net>
Cc: Michael Nolan <htfoot(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-26 14:11:06
Message-ID: 1309097466.2381.13.camel@asus-1001PX.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Le dimanche 26 juin 2011 à 00:05 -0700, Darren Duncan a écrit :
> Michael Nolan wrote:

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

Would you mind giving an example of where a boolean field would be a win
over an integer one?

I'm asking this because I frequently wonder what is best for my use; I
normally query postgres via Perl modules, which don't care about boolean
(the driver converts t/f to 0/1), but I like to tune my fields properly.

--
Vincent Veyron
http://marica.fr/
Logiciel de gestion des sinistres et des contentieux pour le service juridique


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
Cc: Darren Duncan <darren(at)darrenduncan(dot)net>, Michael Nolan <htfoot(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-26 14:41:50
Message-ID: BANLkTinXYPvEepGOu3pcto74PG19g=9hYg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

hello

2011/6/26 Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>:
> Le dimanche 26 juin 2011 à 00:05 -0700, Darren Duncan a écrit :
>> Michael Nolan wrote:
>
>> Having real BOOLEAN is just one of the reasons I like Postgres the most.
>>
>
> Would you mind giving an example of where a boolean field would be a win
> over an integer one?

everywhere, where you require readability. For me a FALSE is more
readable than 1 <> 0 or TRUE instead 1 = 1

Regards

Pavel Stehule

>
> I'm asking this because I frequently wonder what is best for my use; I
> normally query postgres via Perl modules, which don't care about boolean
> (the driver converts t/f to 0/1), but I like to tune my fields properly.
>

sure, it depends on fact if outer environment knows or doesn't know a
boolean datatype.

>
> --
> Vincent Veyron
> http://marica.fr/
> Logiciel de gestion des sinistres et des contentieux pour le service juridique
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
Cc: Darren Duncan <darren(at)darrenduncan(dot)net>, Michael Nolan <htfoot(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-26 16:05:29
Message-ID: 20110626160529.GL32313@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

* Vincent Veyron (vv(dot)lists(at)wanadoo(dot)fr) wrote:
> Would you mind giving an example of where a boolean field would be a win
> over an integer one?

Where you only ever want 2 (or perhaps 2+NULL) values allowed for the
column. It's about domain, consistency, etc, primairly. That said,
don't we implement boolean fields using a bitmap similar to NULLs? In
which case, it would likely be smaller on disk and more performant as
well.

> I'm asking this because I frequently wonder what is best for my use; I
> normally query postgres via Perl modules, which don't care about boolean
> (the driver converts t/f to 0/1), but I like to tune my fields properly.

Yes, which is pretty horrible of it, imo.

Thanks,

Stephen


From: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Darren Duncan <darren(at)darrenduncan(dot)net>, Michael Nolan <htfoot(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-27 02:45:40
Message-ID: 1309142740.2381.22.camel@asus-1001PX.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Le dimanche 26 juin 2011 à 12:05 -0400, Stephen Frost a écrit :
> > (the driver converts t/f to 0/1), but I like to tune my fields properly.
>
> Yes, which is pretty horrible of it, imo.
>

There is an option to turn it off and get the characters t/f returned
(pg_bool_tf)

--
Vincent Veyron
http://marica.fr/
Logiciel de gestion des sinistres et des contentieux pour le service juridique


From: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-27 03:04:27
Message-ID: 1309143867.2381.33.camel@asus-1001PX.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Le dimanche 26 juin 2011 à 16:41 +0200, Pavel Stehule a écrit :

> everywhere, where you require readability. For me a FALSE is more
> readable than 1 <> 0 or TRUE instead 1 = 1
>

Actually, in Perl it's just 0 for false and 1 for true, so it's very
readable if you're used to it.

> >
> > I'm asking this because I frequently wonder what is best for my use; I
> > normally query postgres via Perl modules, which don't care about boolean
> > (the driver converts t/f to 0/1), but I like to tune my fields properly.
> >
>
> sure, it depends on fact if outer environment knows or doesn't know a
> boolean datatype.
>

In that case, I was really wondering from a data modeling standpoint.
Stephen's point seems good (only two values + null).

--
Vincent Veyron
http://marica.fr/
Logiciel de gestion des sinistres et des contentieux pour le service juridique


From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-27 07:12:50
Message-ID: 201106271012.51395.achill@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Στις Sunday 26 June 2011 17:11:06 ο/η Vincent Veyron έγραψε:
> Le dimanche 26 juin 2011 00:05 -0700, Darren Duncan a crit :
> > Michael Nolan wrote:
>
> > Having real BOOLEAN is just one of the reasons I like Postgres the most.
> >
>
> Would you mind giving an example of where a boolean field would be a win
> over an integer one?
>
> I'm asking this because I frequently wonder what is best for my use; I
> normally query postgres via Perl modules, which don't care about boolean
> (the driver converts t/f to 0/1), but I like to tune my fields properly.

Alright, but in other enterprise-level platforms, like java, there is a boolean data type and a Boolean class wrapper.

>
>
> --
> Vincent Veyron
> http://marica.fr/
> Logiciel de gestion des sinistres et des contentieux pour le service juridique
>
>

--
Achilleas Mantzios


From: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-27 10:11:21
Message-ID: 201106271211.21363.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Sunday 26. June 2011 16.11.06 Vincent Veyron wrote:
> Le dimanche 26 juin 2011 à 00:05 -0700, Darren Duncan a écrit :
> > Michael Nolan wrote:
> >
> > Having real BOOLEAN is just one of the reasons I like Postgres the most.
>
> Would you mind giving an example of where a boolean field would be a win
> over an integer one?
>
> I'm asking this because I frequently wonder what is best for my use; I
> normally query postgres via Perl modules, which don't care about boolean
> (the driver converts t/f to 0/1), but I like to tune my fields properly.

PHP has its own Boolean values TRUE/FALSE, but reads Postgresql Booleans as
't'/'f'. You always have to rely on kludgy konstructs like

if ($pg_bool == 't') then
$my_bool = TRUE;
elseif ($pg_bool == 'f') then
$my_bool = FALSE;
else
$my_bool = NULL;

It's of course much easier to use integer values, but it sucks not to use a
bool when you want a variable that can't be anything but TRUE, FALSE or NULL.

It obfuscates the code to use a var that evaluates to an integer, but in
reality is a Boolean in disguise.

regards, Leif


From: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
To: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: An amusing MySQL weakness--not!
Date: 2011-06-27 12:48:20
Message-ID: 1309178900.2381.81.camel@asus-1001PX.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Le lundi 27 juin 2011 à 12:11 +0200, Leif Biberg Kristensen a écrit :
> PHP has its own Boolean values TRUE/FALSE, but reads Postgresql
> Booleans as
> 't'/'f'. You always have to rely on kludgy konstructs like
>
> if ($pg_bool == 't') then
> $my_bool = TRUE;
> elseif ($pg_bool == 'f') then
> $my_bool = FALSE;
> else
> $my_bool = NULL;
>
> It's of course much easier to use integer values, but it sucks not to
> use a
> bool when you want a variable that can't be anything but TRUE, FALSE
> or NULL.
>

Same thing with Perl.

But I am starting to think that the benefits of data integrity
mentionned by Stephen are worth the extra effort : you save on
validation needs anyway, which is probably another couple of lines, if
not more, and less reliable.

--
Vincent Veyron
http://marica.fr/
Logiciel de gestion des sinistres et des contentieux pour le service juridique