If I'm doing:
session.execute('select some_numeric from some_table')
...how do I get floats back in the result instead of decimals?
Chris
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>
I can't quite join the dots on this one...
I get passed a bunch of sql to execute, I don't have control over that.
Where do I wire in Numeric(as_decimal=False) and how do I tell where I
need to given an arbitrary select as a string of sql?
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
> On 13/10/2010 22:37, Michael Bayer wrote:
>> use text() with Numeric(as_decimal=False)
>
> I can't quite join the dots on this one...
>
> I get passed a bunch of sql to execute, I don't have control over that.
> Where do I wire in Numeric(as_decimal=False) and how do I tell where I need to given an arbitrary select as a string of sql?
text() is in the docs, including an example of typemap:
Okay, but I don't see how a typemap helps.
All I'm getting is a string of sql, I don't know what column names are
included in that, and even if I did, I wouldn't know the schema of the
table to know what they should be mapped to.
How can I influence what column type is mapped to a particular python
type without knowing the names or types of the columns?
cheers,
Chris
> On 14/10/2010 17:10, Michael Bayer wrote:
>>
>>> I get passed a bunch of sql to execute, I don't have control over that.
>>> Where do I wire in Numeric(as_decimal=False) and how do I tell where I need to given an arbitrary select as a string of sql?
>>
>> text() is in the docs, including an example of typemap:
>>
>> http://www.sqlalchemy.org/docs/core/expression_api.html?highlight=text#sqlalchemy.sql.expression.text
>
> Okay, but I don't see how a typemap helps.
> All I'm getting is a string of sql, I don't know what column names are included in that,
If you don't know your columns, neither does SQLAlchemy. Depending on your DBAPI you may be able to get the DBAPI itself to not use the Decimal type, see the docs on your DBAPI for information on type coercion at the DBAPI level.
Otherwise, you'd filter your result set, do isinstance(x, Decimal), convert to float. You may be able to use result.cursor.description if the DBAPI returns reasonable types. We could someday add an execution_option() that allows a map of DBAPI types mapped to result types to be passed.