any expression in SQL can be coerced into a particular type using
casts.   PG supports the SQL standard CAST operator which SQLAlchemy
provides as expression.cast, i.e.

from sqlalchemy import cast, Integer

cast(somevalue + someothervalue, Integer)

This will instruct PG to cast the value as integer and also allow
SQLAlchemy to treat the expression construct as an int in python.



On Jul 5, 1:53 pm, Pongetti <owendea...@gmail.com> wrote:
> Hello,
>
> I have a View in a Postgres DB with some calculated columns.  In
> Postgres the column types are getting "lost", so essentially, despite
> all the math being on integers, Postgres is spitting out columns with
> the type Numeric instead of type Integer.
>
> Using SQLAlchemy, I am therefore getting values wrapped in Decimal
> functions rather than the native Python Int type.  So for example, I
> get Decimal("4") instead of just 4.
>
> I have been using autoload but even if I override the column types in
> SQLAlchemy to be Integers, I am still getting Decimal("n").
>
> Any help on how I could best get a plain old int would be most
> appreciated.  The ORM is a bit overkill for my project, I really just
> need the SQL Expression language, so a solution not involving the ORM
> would be preferred, though I will use it if I need to.
>
> Thank you!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to