you should be able to say:

group_by("first_letter")

should go right in under that label.

works for order by at least.


On Jul 23, 2014, at 7:31 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote:

> I want to generate this SQL:
> 
>         SELECT 
>             SUBSTR(domain_name, 1, 1) as first_letter, 
>             COUNT(domain_name) as counted
>         FROM domain
>         GROUP BY first_letter;
> 
> The closest I can get to it is this:
> 
>         dbSession.query(
>             sqlalchemy.func.count( model.Domain.domain_name 
> ).label('counted'),
>             sqlalchemy.func.substr( model.Domain.domain_name, 1, 1 
> ).label('first_letter'),
>         ).group_by(
>             sqlalchemy.func.substr( model.Domain.domain_name, 1, 1 )
>         )
> 
> I tried using this as a the group by:
> 
>     sqlalchemy.sql.expression.literal('first_letter')
> 
> however postgres doesn't like the group by coming in as a bind param.
> 
> is there another way to construct the intended query, or do I have to use 2 
> substring operations (or a subquery)?
> 
> -- 
> 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 http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to