Hello all,

I am in the process of trying to create a dynamic expression query engine 
in an application I'm working on.

So there is a formula that gets defined like so: 

formula = '"metric:123" + "metric:456" + "metric:789"'

Each metric maps to a column in the database tables - long story short, I'm 
able to retrieve the metric by ID, and instantiate an InstrumentedAttribute 
object that has the SQLAlchemy metadata for the associated column. What I'm 
trying to achieve is to be able to iterate through the formula, and 
dynamically build a SQLALchemy query that maps to the formula.

For example, the formula defined above would look something like this in 
SQL:

SELECT post.id + campaign.id + asset.id
FROM post, campaign, asset
WHERE ......;

The idea is to translate the above to something like:

session.query(<sqlalchemy.orm.attributes.InstrumentedAttribute object at 
0x7ff9269f92b0> + <sqlalchemy.orm.attributes.InstrumentedAttribute object 
at 0x7ff9269c5990> + <sqlalchemy.orm.attributes.InstrumentedAttribute object 
at 0x7ff926896048>).all()

I've tried a couple of approaches of dynamically generating the SQLAlchemy 
ORM query, but I haven't been able to find anything that works. Would 
anyone have any idea or tips on how to accomplish this?

Thank you!

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