On 06/24/2017 09:44 PM, phix1...@gmail.com wrote:


Am Freitag, 23. Juni 2017 05:25:41 UTC+2 schrieb Mike Bayer:



    return my_col * literal(0.5, Float())


Hello Mike,
thank you for the quick response.

This doesn't seem to fully work when querying the value using session.query(MyObject.my_hybrid_expression).scalar().

https://bitbucket.org/zzzeek/sqlalchemy/issues/4018/maintaining-float-type-affinity is added as a proposal to use something more specific than type affinity for this match however as always, these are all convenience behaviors that are tunable when they fail to produce the desired effect; you can control the exact type of any expression using type_coerce() or cast():

from sqlalchemy import Float, Integer, literal, Numeric, type_coerce
expr = literal(5, Integer) * literal(4.5, Float)

expr = type_coerce(expr, Numeric(asdecimal=False))

assert expr.type.asdecimal is False



From the
callstack, the Numeric (possibly representing the result of the multiplication) now seems to be initialized by type_api.py:to_instance, which calls the Numeric constructor without passing any **kwargs, so it again defaults to asdecimal=True. This method is called by sqltypes.py:_DateAffinity.Comparator._adapt_expression, which finds MyFloat._type_affinity == Numeric.

Greetings,
Phillip

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
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 sqlalchemy+unsubscr...@googlegroups.com <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to