1

I have a schema with a Float column, something like this:

Base = declarative_base()
class Table(Base):
    __tablename__ = 'table'
    id = Column(Integer,primary_key=True)
    amount = Column(Float(16,2))

When I commit some rows to this table, sqlalchemy rounds the floating point numbers to integers:

t = Table()
t.amount = 2.25

session.add(t)
# right here, t.amount is still 2.25
session.commit()
# here, t.amount is already 2

Doing some SQL on my DB gives this:

SELECT * FROM Table

id  | amount
-------------
 1  | 2

Is there a reason that this may be happening? Some missing or wrong configuration? I have also tried using Numeric data type, but the result is the same

I'm using sqlalchemy 0.8.2 with a MySQL db here

Javier Novoa C.
  • 11,257
  • 13
  • 57
  • 75

1 Answers1

1

hummmm I think it had to do with the precision parameters. Using Numeric, it's working! I used Numeric before, but forgot to use the precision parameters.

Please excuse me, this question has the answer...

Javier Novoa C.
  • 11,257
  • 13
  • 57
  • 75