On Jan 9, 2008, at 6:57 AM, Christoph Zwerschke wrote:

> Now I want to get all different cities of my customers, starting with
> 'A', ordered alphabetically. In plain SQL this would be:
...

> But this does not work, since the select statement does not return the
> attribute set of the Customer class.

these two  statements seem to contradict; do you want a collection of  
strings representing each "city" ?  or do you want Customer objects ?   
or the full set of columns represented by a Customer ?

The basic request to get cities as strings by themselves should be  
easy enough as:

select 
([Customer 
.city]).distinct().order_by(Customer.city).execute().fetchall()

>
> Bonus question: How can I make the comparison case insensitive, i.e.
> create a where clause like that:

> ... where city ilike 'A%' ...
> or
> ... where lower(city) like 'a%'
>

select 
([Customer 
.city 
]).distinct 
().order_by(Customer.city).where(func.lower(Customer.city).like("a 
%")).execute().fetchall()

we will eventually have a database-neutral "ilike" comparator but that  
hasn't been implemented yet.

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