[Tutor] MySQLdb: dropping zeroes!

Tim Johnson tim at johnsons-web.com
Wed Apr 14 14:29:25 EDT 2004

* Magnus Lyckå <magnus at thinkware.se> [040413 16:15]:
> At 07:56 2004-04-07 -0800, Tim Johnson wrote:
> >  To quote the mysql manual:
> >
> >   "The DECIMAL type is considered a numeric type (as is its synonym,
> >   NUMERIC), but such values are stored as strings."
> >
> >   So I thought there might be a way to override the
> >   MySQLdb type conversion and get them back as strings.
> The problem (which I hope will be fixed in a not too far future)
> is that Python lacks a standard decimal type/class.
  :-) Knowing python folks, I know that you will do it right
      and do it carefully....

> ADODBAPI does it the other way around, and returns DECIMAL
> as strings, and that's not without problems either. For
> instance, with e.g. Swedish settings in Windows, 1/2 will
> be returned as '0,5', not '0.5', and float('0,5') won't make
> Python happy.

> Anyway, I guess you could replace "SELECT X FROM Y" with
> "SELECT CAST(X AS CHAR(10)) AS X FROM Y" or something like
> that.
  That is a really good tip. Always best to try to make
  mysql to as much of the work as possible IMHO.
  Didn't know about 'CAST' and will research it.

> --
> Magnus Lycka (It's really Lyck&aring;), magnus at thinkware.se
> Thinkware AB, Sweden, www.thinkware.se
> I code Python ~ The Agile Programming Language 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

Tim Johnson <tim at johnsons-web.com>

More information about the Tutor mailing list