Damien Tougas wrote:
> Hello,
>
> I am new at this, so I am sure that this is easy. I understand how the
> mapper works, and I can get it working fine when mapping tables to
> classes. What I need to do is map the following select statement to a
> class:
>
> SELECT function_name(column_name) AS c1 FROM table_name
>
> The usage of the function as part of the select statement is causing
> me some problems. Initially I tried this:
>
> table = Table('table_name', metadata, Column('column_name', Integer,
> primary_key=True))
> sel = select ([table.c.column_name, 'function_name(column_name) AS
> c1'], from_obj=[table]).alias()
> mapper(ClassName, sel)
>
> That didn't work correctly, so I am somewhat at a loss as to how to
> handle that function in the select statement. Does anyone have any
> suggestions?
>
>
See
http://www.sqlalchemy.org/docs/05/mappers.html#mapping-a-class-against-arbitrary-selects
for an example for mapping to arbitrary selects. In your case, it would
be something like:
sel = select([func.function_name(table.c.column_name).label('c1'),
from_obj=table).alias('some_alias')
Not sure if the alias part is needed.
-Conor
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.