Hello,

I am trying to use SQLAlchemy to generate queries against introspected 
tables, based on filter expressions that I parse from another 
domain-specific language.  I have it mostly working, except that I want to 
be able to use aggregate-type functions in the DSL, and have them work 
properly in SQLAlchemy's generated SQL.  

The code construct I use in my "running functions" code to do this is this 
(in essence):


fn = getattr(sqlalchemy.func, fname)(*fargs)

return fn


...where "fname" is the function name and "fargs" the argument list.  The 
returned fn is then applied to a query object using query.filter().

This all works fine for normal functions, but aggregates of course trigger 
error messages like "misuse of aggregate function" from SQLite, or 
"aggregates not allowed in WHERE clause" from PostgreSQL, or the like.  

I have found that I can "whitelist" a few commonly-known aggregates (min, 
max, avg, count, sum), and issue a call to fn.select() to wrap that 
function call in a subquery before returning it.  This works, but 
whitelisting specific aggregate functions is not only tedious, but 
error-prone, and not very extensible.

Is there a property or method I can use in the SQLAlchemy Function objects 
to determine if a Function object represents an aggregate? 

Thanks very much,

Avi Blackmore

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to