On Sep 13, 2009, at 5:32 AM, Eric Lemoine wrote:

>
> Hello list
>
> I have a simple mapping between a class and a table. What I'd like to
> be able to do is dynamically change the query selection (based on some
> HTTP param). More precisely I'd like that the ORM generate
>
> SELECT some_sql_function(col1), col2, col3 FROM ...
>
> instead of the default
>
> SELECT col1, col2, col3, FROM ...
>
> And, as I said, I'd like this to be dynamic, so I don't want this to
> be hardwired in my mapping definition. Is this possible?
>
> Thanks a lot,


the most straightforward way is to use the Query in that fashion:

query(func.some_sql_function(MyClass.col1), MyClass.col2, MyClass.col3)

However, i suspect you might be wanting to load MyClass instances with  
the value of "col1" replaced.    it might be easiest just to say:

query(func.some_sql_function(MyClass.col1), MyClass)

and then manually piece together the first column onto the instances  
as they are received.

The third way which is the least visually appealing is to use  
query.from_statement(), rows from any statement you pass within will  
be mapped to the columns based on names.    the statement within can  
be a select() construct or a string, or you can even use another Query 
() and then call "query.statement" on it to get at the select().


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

Reply via email to