Hi Mike, thanks for your quick response.

Im just using decimal.Decimal all over the code, no cDecimal.

o.amount behaves like a Decimal in fact his type is Decimal.
if i do dir(o.amount) it shows all the methods of class Decimal.


But if i try to compare with another Decimal.

o.amount.compare(Decimal('10'))

File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py",
 
line 5853, 
in _convert_other raise TypeError("Unable to convert %s (%s) to Decimal" % 
(other, type(other))) TypeError: Unable to convert 10 (<class 
'decimal.Decimal'>) to Decimal

*And if i do.*

Decimal('10').compare(o.amount)
File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py",
 
line 5853, 
in _convert_other raise TypeError("Unable to convert %s (%s) to Decimal" % 
(other, type(other))) TypeError: Unable to convert 1000.00000000 (<class 
'decimal.Decimal'>) to Decimal

*And this works ...*

print o.amount.compare(o.amount)    --->  0


Never run into a similar situation, are there any specific Decimal 
management in sqlalchemy? (besides what the documentation says)

(i'm using python2.7 from port OSx 10.7.6)
Python 2.7.8 (default, Jul 13 2014, 02:30:56) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin















On Wednesday, October 8, 2014 3:44:14 PM UTC-3, Michael Bayer wrote:
>
>
> On Oct 8, 2014, at 2:14 PM, Marty <[email protected] <javascript:>> 
> wrote: 
>
> > I have a column defined as 
> > 
> > class Balance(Base): 
> >   .. 
> >   amount  = Column(DECIMAL('16,8'), default=Decimal('0')) 
> >   .. 
> > 
> > 
> > o = db.query(Balance).get(1) 
> > 
> > 
> > Everything goes fine ... 
> > 
> > type(o.amount)     => 'Decimal' 
> > 
> > but 
> > 
> > isinstance(o.amount, Decimal)   => False 
> > 
> > 
> > Im porting from a noSql database and somewhere in the code i have a call 
> to Decimal.quantize that check types using "isinstance" 
> > 
> > 
> > Question: How do i pass the isinstance check with an instance of Column? 
>
> if type(o.amount) is Decimal then that’s what it should be…are there more 
> than one Decimal class in play, are you using cDecimal in some places for 
> example?  cDecimal and Decimal aren’t cross-compatible and there’s a 
> special hack to use cDecimal across the board. 
>
>
>
>

-- 
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.

Reply via email to