On Jul 12, 2014, at 4:49 AM, Staszek <[email protected]> wrote:
>
> Not really, no, yes.
>
> The problem seems to have been with assignment of float values. It was
> like this:
>
> base.py:847: UPDATE buildings SET glatitude=%s, glongitude=%s WHERE
> buildings.id = %s
> base.py:849: (52.0210673, 20.2152834, 1)
>
> It can't be seen here, but then I guess those float values were being
> converted by SQLAlchemy to decimals like:
>
> Decimal('52.021067299999998567727743647992610931396484375')
the Numeric type deals with Decimal objects. add usedecimal=False to deal
with floats. It only does a float <-> Decimal conversion if the backend
doesn't support it.
>
> which was not equal to the value stored in the column because it has
> lower precision.
>
> However after converting those new values to Decimal *and* quantizing:
>
> d = Decimal('0.00000001')
> glat = Decimal.from_float(glat).quantize(d)
> glon = Decimal.from_float(glon).quantize(d)
>
> the new Decimals are equal to the old Decimals and I can see no UPDATE
> in the log.
>
> Not sure how it exactly works on SQLAlchemy side
it doesn't emit an UPDATE when the value that was loaded matches the value that
it was modified to, using ==.
> but perhaps it could
> make sense to take the column precision into consideration when
> comparing decimals on assignment/update.
See decimal_return_scale at
http://docs.sqlalchemy.org/en/rel_0_9/core/types.html?highlight=numeric#sqlalchemy.types.Numeric.__init__.
However, consider that the MySQL driver can be involved in decimal conversion
operations as well; I'm not sure offhand which side does what in the case of
MySQL.
If decimal accuracy is of any concern, you should be using Decimal objects
fully, never a Python float, and if you are using a Numeric without
asdecimal=False this is more appropriate.
None of this has anything to do with your original issue with the UPDATE not
matching any rows, however. The UPDATE here is not matching on the integer
primary key.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.