> Nah!  I think I'd prefer to do it myself and have the compiler/interpreter
> come up saying "hey buddy, what ya trying to do?  This ain't no number"
> rather than it changing the number into string and happily continue on
> running through the rest of the programming.  Takes you longer to figure out
> you used the letter "O" instead of the number 0.

Strong typing and weak typing each have their merits.

When MySQL compares numbers and strings, it does so by converting the
string to a number, rather than the number to a string (which would
seem more natural in a type-heirarchy sense, but would be confusing).

So my question is, if it 'demotes' strings to numbers when comparing
them with or assigning them to numeric fields, then why would it ever
make a difference to quote numeric literals?

And in practice, it has appeared to me to make no difference.  (Until
some recent bug report regarding bigints where it did appear to make a
difference.)

It was pointed out to me that there is an efficiency difference:

    select benchmark(1000000, 1+1);    =>   0.34 sec
    select benchmark(1000000, 1+'1');  =>   1.81 sec

which, though true, would usually not matter.

My personal preference would be that if it could ever matter to quote
numeric literals, then disallow that (or at least provide a switch
that disallows it (and one that only warns), so as not to break a lot
of code).  If the policy is that it should not ever matter to quote
numeric literals, then treat as bugs the cases where it turns out to.

--
Pete Harlan
[EMAIL PROTECTED]  (Is "Antwort" Swedish?)


> > Tis true Rolf but you can bet your bottom dollar that at somepoint
> > a confusion will arise when it is most inconvenient.  There is
> > always a conversion somewhere in the code even if it is not
> > visible.
> >
> > > -----Original Message-----
> > > From: Rolf Hopkins [SMTP:[EMAIL PROTECTED]]
> > > Sent: 23 February 2001 02:09
> > > To: Julian Strickland; [EMAIL PROTECTED]
> > > Subject: Re: Quoting numbers? (was Re:MySQL Tables)
> > > 
> > > That's very true but these days, some languages/databases allow
> > > for strings to be assigned to numbers and vice versa without the
> > > need for conversion.  PHP is one such language, not that I'm
> > > bagging it or anything as I use it myself.  I just call it bad
> > > type checking.
> > >
> > > ----- Original Message -----
> > > From: "Julian Strickland" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Thursday, February 22, 2001 22:35
> > > Subject: RE: Quoting numbers? (was Re:MySQL Tables)
> > >
> > > It's all to do with data types, traditionally and across most
> > > > languages quotes are used to delimit STRINGS and a string is
> > > > NOT a number although may represent one when displayed.
> > > >
> > > > > -----Original Message-----
> > > > > From: Pete Harlan [SMTP:[EMAIL PROTECTED]]
> > > > > Sent: 21 February 2001 20:51
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: Quoting numbers? (was Re:MySQL Tables)
> > > > >
> > > > > > I think you'll get better results if you don't quote your
> > > > > > numbers. Quotes should be used for text and dates
> > > > > > (depending) but not numbers.
> > > > >
> > > > > Out of curiosity, why?
> > > > > 
> > > > > We use quotes for numbers all the time here, for
> > > > > consistency's sake; the programmer doesn't have to worry
> > > > > about the representation of, say, a salesman_id, but just
> > > > > reads/displays/stores it in the database.
> > > > > 
> > > > > Aside from the fact that leaving them off is possible, is
> > > > > there a standards/compatibility/other reason to do so?
> > > > > 
> > > > > (An example of a good reason not to use them would be if the
> > > > > db engine weren't smart enough to use an index when you say
> > > > >
> > > > > select * from table_name where numeric_key = '1234'
> > > > >
> > > > > but possibly (probably?) all dbms's are that smart.)
> > > > >
> > > > > --Pete

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to