[英]Numeric asdecimal ignored and variable is float type
Using SQLAlchemy 1.3.5, Postgres 9.6, and Python 3.6.8 a field on a model is defined as Decimal
via price = Column(Numeric(asdecimal=True))
however printing out the model's type shows its a float:
subscription.price
2.5
(Pdb) type(subscription.price)
<class 'float'>
如何让 SQLAlchemy 使用Decimal
类型?
该文档甚至说指定asdecimal
是不必要的,因为它是默认值:
This type returns Python ``decimal.Decimal`` objects by default, unless
the :paramref:`.Numeric.asdecimal` flag is set to False, in which case
they are coerced to Python ``float`` objects.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.